The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Fortean Jo on September 13, 2005, 07:30:13 PM

Title: Declaring a variable of my_struc?
Post by: Fortean Jo on September 13, 2005, 07:30:13 PM
I'm writing a piece of code in Masm that uses a struc similar to this:

     my_struc     struc
          Field1      db 128 dup (?)
          FieldLen   dd ?
          Field2      db 128 dup (?)
          FieldLen   dd ?
     my_struc     ends


I then want to declare an unitiliased array with several thousand elements, each of type my_struc, so I'm using something like this:

     my_struc_array     my_struc     8192 dup (<>)

However, masm takes ages to actually assemble the file that declares this.  Without my_struc_array, the project is assembled in about 15 ms.  If I declare it, it can take about 20 mins.

The question is, then: Am I going about this the wrong way - I need the array but how should I declare it?
Title: Re: Declaring a variable of my_struc?
Post by: Phoenix on September 13, 2005, 08:08:01 PM
Fortean Jo,

if I'm not completly wrong you are trying to reserve 2,228,224 bytes = 2,176 KBytes = 2.125 MByte of memory......
Perhaps you should use LocalAlloc or similar for the required size of memory and work with ASSUME and pointers to access the data you need?

Just an idea, regards
Phoenix
Title: Re: Declaring a variable of my_struc?
Post by: tenkey on September 13, 2005, 10:38:28 PM
This is a known PERFORMANCE BUG in MASM when generating COFF object files.
You can either create the alternate OMF object file, or use dynamic memory allocation functions, such as HeapAlloc.
Title: Re: Declaring a variable of my_struc?
Post by: hutch-- on September 14, 2005, 03:39:52 AM
Fortean Jo,

Its not a good tchnique for a couple of reasons, MASM is known to be very slow on large static arrays and similar data allocaions but with the resulting file with the array of structures in the uninitialised data section, the static memory demand is set at the size of the amount of static data you have set up. Any of the dynamic allocation APIS will do what you need.

It will depend on how you wish to access each structure but there is an array allocation procedure in the MASM32 library that will do what you are after if you need each sructure referenced by a pointer.

create_array proc acnt:DWORD,asize:DWORD

It returns the raw array address and the address of an array of pointers to each array element so you would just nominate the count you wanted and the size of each element. I think your structure is 264 bytes in length but make sure if you use it that each element in the allocated array is 4 byte aligned.