Does anyone have a quick (translation: fast) substitute routine in EBasic for the redim command? I'm working on a large parsing project and want to (constantly) reuse a working array - but it has to be totally cleaned out between each use. Yes, I'm aware I could write a short for loop to do it - just wondering if there are any other options.
Thanks in advance.
Tom
Do you just want to set the elements of an existing array to zero? Or are you trying to change the size of an array?
The array size will remain the same - just need to clear them (text labels) between records.
Tom
DECLARE IMPORT,ZeroMemory ALIAS RtlZeroMemory( POINTER pvoid,INT length),INT
def a[10] as string
def d[100] as double
//ZeroMemory(array, elements * size)
ZeroMemory(a, 10 * 255)
ZeroMemory(d, 100 * 8)
Quote from: Paul Turley on January 08, 2007, 11:32:25 AM
Do you just want to set the elements of an existing array to zero? Or are you trying to change the size of an array?
Ok. Suppose that I have an array that "grows." I want to add more rows to an array while preserving the current contents. Can I do this without delclaring a new array and copying the old array into it?
Suppose I don't know the array size untill run time. For example, I want to parse a CSV file with an unknown number of fields until I read it. Would this be done with "new" and using pointers?
Regards,
Bob
Although haven't tried this...
def a[] as string
// do stuff until you need the array
a[size] as string
ZeroMemroy(a,10*255)
You have to use NEW and a pointer if you want to have an array at runtime. As explained in another thread, arrays that are defined like:
def a[100] as INT
Are not allocated, they are reserved in memory (the process address space) by the OS when the executable is loaded. It is a fixed size and cannot be changed once compiled. Using allocated arrays is not difficult though:
pointer p
p = new(INT, size)
#p[index] = value
print #p[index]
delete p
To change the size of the array you have two choices. Use GlobalRealloc from the Windows API or allocate a second array the new size and copy the old contents.
Paul.
Thank you all for your help.
The solution is very straight-forward.
Regards,
Bob
Gee, my simple little question leads to all sorts of useful information.
Thanks, guys!!!
Tom