Exetools

Exetools (https://forum.exetools.com/index.php)
-   General Discussion (https://forum.exetools.com/forumdisplay.php?f=2)
-   -   GlobalAlloc() (https://forum.exetools.com/showthread.php?t=4277)

Janus68 05-15-2004 03:50

GlobalAlloc()
 
There i have an small problem:
I need allocate many small chunks of memory - i use GlobalAlloc(),
the allocated mem. pointers i collect in array - and after using for freeing i call GlobalFree() for all pointers collected in this array - all is good until i use less than 16384 pointers , if i use more , i see message : "system resources exhausted" or something similar.
Any solulutions ?

gigaman 05-15-2004 04:22

How about using VirtualAlloc instead?
Or have you any special reason why GlobalAlloc has to be used?

koyaan 05-15-2004 10:42

why do you have to allocate so many small chunks?
cant you just pre-alloca te bigger chunks and make up your array of pointers
like

allocate big buff;
for(i=0; i<unameit; i++)
pointer[i] = buff + i*20;

cheers
koyaan

sgdt 05-15-2004 11:08

While I would echo what everyone has said, I would also like to point out you didn't give enough information, such as what OS your running, what your parameters are to GlobalAlloc, and how much actual memory you have in your machine.

But first, the obvious. If your allocating handles, make sure you realise that they are a FINITE resource per process. Second, if you allocate lots of VirtualAllocs, please understand they always start on a page boundry, and you have only 2GB of process space you can map it into (i.e. lots of little VirtualAllocs will eat into your address space pretty fast).

Same is true for threads. I can't tell you how many times I've ran into situations where someone says "I can only get just under 2000 threads". Did you check where ESP was pointing on thread entry? It's about a meg higher than the previous thread, isn't it? Decrease the thread stack size so the computer can map it in! Duh!

Anyway, need more info.

Janus68 05-16-2004 03:35

Thanx all :)

Problem resolved with allocation big table and array of pointers - as koyaan says.These "chunks" are allocated structures in an symbol table - the part of compiler.

Regards.
Janus.

doug 05-16-2004 05:53

@gigaman:

About VirtualAlloc:

dwSize
in: Size of the region, in bytes. If the lpAddress parameter is NULL, this value is rounded up to the next page boundary. Otherwise, the allocated pages include all pages containing one or more bytes in the range from lpAddress to (lpAddress+dwSize). This means that a 2-byte range straddling a page boundary causes both pages to be included in the allocated region.


so even if you allocate 1-byte using virtualAlloc, the system will reserve an entire page (4KB).

gigaman 05-16-2004 19:06

I know - but the original post didn't say how big these "chunks" are. I was just trying to get some more information. Of course, allocating a bigger piece of memory and doing your own handling of smaller memory allocation is better, just requires some additional work.

Btw, even for GlobalAlloc the documentaion says that bigger piece of memory than the requested one may be allocated.

koyaan 05-17-2004 03:11

MSDN discourages the use of GobalAlloc
maybe you should use the heap functions
hxxp://msdn.microsoft.com/library/en-us/memory/base/heap_functions.asp


All times are GMT +8. The time now is 19:38.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2026, vBulletin Solutions, Inc.
Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX