News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

A good array example ...

Started by James Ladd, May 08, 2005, 05:23:57 AM

Previous topic - Next topic

James Ladd

Im looking for a good and elegant example of allocating an array and then populating
each element with another allocation of a structure.
ie: each element of the dynamic array is a pointer to a block of memory.
Im also looking for the example to clean up that array by iterating through the array
and freeing each element, then the array itself.

I know its not super hard, but im looking for an elegant solution rather than the hacky job
I think I have done.

rgs, striker.

hutch--

James,

Have a look at this proc in the MASM32 library.


create_array proc acnt:DWORD,asize:DWORD

comment * ---------------------------
    acnt  = number of items in array
    asize = byte count for each item
    ------------------------------- *


Just pass your element count and byte count for each member and when you have finished with it, deallocate the two handles.

You get 2 return values, one for the main memory and the other for the array of pointers to the main memory.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

James Ladd


Randall Hyde

Quote from: striker on May 08, 2005, 05:23:57 AM
Im looking for a good and elegant example of allocating an array and then populating
each element with another allocation of a structure.
ie: each element of the dynamic array is a pointer to a block of memory.
Im also looking for the example to clean up that array by iterating through the array
and freeing each element, then the array itself.

I know its not super hard, but im looking for an elegant solution rather than the hacky job
I think I have done.

rgs, striker.

The chapter on Arrays in Art of Assembly discusses all this stuff. See http://webster.cs.ucr.edu/AoA/Windows/HTML/Arrays.html#1003722
Cheers,
Randy Hyde