Exetools  

Go Back   Exetools > General > General Discussion

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 05-15-2004, 03:50
Janus68
 
Posts: n/a
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 ?
Reply With Quote
  #2  
Old 05-15-2004, 04:22
gigaman gigaman is offline
Friend
 
Join Date: Jun 2002
Posts: 87
Rept. Given: 0
Rept. Rcvd 3 Times in 2 Posts
Thanks Given: 0
Thanks Rcvd at 14 Times in 11 Posts
gigaman Reputation: 4
How about using VirtualAlloc instead?
Or have you any special reason why GlobalAlloc has to be used?
Reply With Quote
  #3  
Old 05-15-2004, 10:42
koyaan
 
Posts: n/a
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
Reply With Quote
  #4  
Old 05-15-2004, 11:08
sgdt
 
Posts: n/a
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.
Reply With Quote
  #5  
Old 05-16-2004, 03:35
Janus68
 
Posts: n/a
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.
Reply With Quote
  #6  
Old 05-16-2004, 05:53
doug
 
Posts: n/a
@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).
Reply With Quote
  #7  
Old 05-16-2004, 19:06
gigaman gigaman is offline
Friend
 
Join Date: Jun 2002
Posts: 87
Rept. Given: 0
Rept. Rcvd 3 Times in 2 Posts
Thanks Given: 0
Thanks Rcvd at 14 Times in 11 Posts
gigaman Reputation: 4
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.
Reply With Quote
  #8  
Old 05-17-2004, 03:11
koyaan
 
Posts: n/a
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
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



All times are GMT +8. The time now is 21:17.


Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX, chessgod101
( Since 1998 )