The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: cobold on May 23, 2008, 08:39:25 PM

Title: Dynamic array? or how to create array at runtime
Post by: cobold on May 23, 2008, 08:39:25 PM
Hello,

is there a way to create an array dynamically or at runtime in Assembler? The only way I know so far creates static arrays only:
f.ex.

.data
SomeArray DWORD NbrOfElements dup(?)


This is the only method I know and it was fine so far. But NbrOfElements must be a constant value, so you end up with fixed sized, static arrays. Now it would be fine to have a bit more flexibility. (I know there's a function to allocate memory at runtime, but how do you tell the assembler: "use this memory for SomeArray"?)
What I want to do is either:
-  predefine SomeArray with let's say 1000 Elements, and then depending on user-input I want to resize the Array (make it smaller or larger)
or
- don't define the array in advance, but after user-input I want to calculate the size I need at runtime, allocate the required memory and assign this memory to SomeArray.

Any hints how to do this?
Thanks in advance!

cobold
Title: Re: Dynamic array? or how to create array at runtime
Post by: jj2007 on May 23, 2008, 08:53:31 PM
Hutch has started at least dedicated two dedicated threads, try this (http://www.masm32.com/board/index.php?topic=9165.msg66448#msg66448) and that (http://www.masm32.com/board/index.php?topic=9006.0).
Title: Re: Dynamic array? or how to create array at runtime
Post by: hutch-- on May 24, 2008, 12:51:46 AM
I have got the new system finished, it needed to be faster in a few places than the prototypes I had tried out but the problem is I now have it as part of the masm32 library for version 10 and have the help file more or less done for it but the new version is not ready yet for posting.

The prototype system worked OK but the original array allocation was slower than it needed to be through allocating an empty array member where the new version uses a single fixed null length string for empty strings that made it both faster and used less memory.

If you used the old system with its macro interface the new system is compatible but the new system has both a macro and procedure interface and is structured a bit differently so you could not use the old system as procedures and then use the new system on top of it.