News:

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

Memory - big chunk or small chunks

Started by RedXVII, April 05, 2007, 10:17:34 PM

Previous topic - Next topic

RedXVII

I am allocating some memory to some large arrays (in total these "large arrays" are ~4400 bytes in size). But I have a quite a few of these I need to allocate. Performance speaking, would it be better if I GlobalAlloc the whole lot of them into one large chuck, or GlobalAlloc them seperately into respective small chunks, or would this end up just being the same performance wise?

Cheers  :U
Red

dsouza123

Too bad the arrays aren't 4096 bytes in size, then they would be match the size of a memory page.

How long are they used ?
The life of the program run or repeatedly created and destroyed,
or can they be reused.

Since they aren't multiples of a page size then allocating many separate ones is less efficient,
each 4400 needing two pages, if one chunk then only one partial page or maybe even none
would be needed.

None if for example 256 arrays of 4400 bytes were allocated.

Are they accessed by variable name or by offset from a base address ?

hutch--

Red,

If you can organise it and round up the allocated size to ensure it is aligned properly, a single large allocation is a better proposition especially if you allocate an array of pointers to each member of the original allocated memory.

If you go the route of many small allocations I would be inclined to go with HeapAlloc() as it seems to have the legs for this style of allocation. If alternatively you go for a large single allocation GlobalAlloc() using the fixed memory flag does the job fine.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

PBrennick

I like Hutch's suggestion to use HeapAlloc. Start with GetProcessHeap, then HeapAlloc space for the array member. Keep track of the count of arrays so if you want them all allocated at the same time, you can do it in a loop. When you are done using them, you can then use a loop to do the HeapFree of all the reserved memory. If you are accessing them one at a time, then consider using HeapReAlloc.

Paul
The GeneSys Project is available from:
The Repository or My crappy website