Re: Limits to memory allocated in DLL
- From: Stephen Kellett <snail@xxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 19 Jan 2006 11:54:34 +0000
In message <1137669827.453829.13840@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
"divya_rathore_@xxxxxxxxx" <divyarathore@xxxxxxxxx> writes
>Hi! Everybody,
>
>Is there any limits to the amount of memory that can be allocated
>inside a DLL?
>I am creating the following array inside a dll:
>
>double array [150000]; //crashes
>
>On calling the dll from the application, the error message says:
>"unhandled exception ..... 0xC00000FD: Stack Overflow"
If your code is allocated globally then a 150,000 element array of
doubles consumes 8 * 150,000 or approx 1.2MB as sizeof(double) is 8
bytes. Should be no problem, it goes in the BSS or DATA sections of the
DLL.
However since you mention Stack Overflow it is clear you are not
allocating this memory in the DLL, but on the stack. Given the default
size of your stack is 1MB and you are allocating an array larger than
that your problem is clear.
This one comes up time after time after time. People try to allocate
very large arrays on the stack. Unsurprisingly, they have problems. The
solution is to allocate your array either globally or dynamically. If
dynamically you will need to decide when to dispose of it. Most people,
myself included, will generally recommend the dynamic approach unless
your application has a short lifetime and the use of a globally
allocated array is not going to cause maintenance issues.
void myGreedyFunc()
{
double *lotsOfDoubles;
lotsOfDoubles = new double [150000]; // eat 1.2MB of memory
... do some work
delete [] lotsOfDoubles;
}
Note that for very large array sizes getting contiguous chunks of memory
can get hard. For example a 1GB dynamic array may be hard to achieve.
Tools such as VM Validator can usually demonstrate this for you in
graphical form very easily. VM Validator is free and can be found at
softwareverify.com
Stephen
--
Stephen Kellett
Object Media Limited http://www.objmedia.demon.co.uk/software.html
Computer Consultancy, Software Development
Windows C++, Java, Assembler, Performance Analysis, Troubleshooting
.
- Follow-Ups:
- Re: Limits to memory allocated in DLL
- From: divya_rathore_@xxxxxxxxx
- Re: Limits to memory allocated in DLL
- References:
- Limits to memory allocated in DLL
- From: divya_rathore_@xxxxxxxxx
- Limits to memory allocated in DLL
- Prev by Date: Re: Limits to memory allocated in DLL
- Next by Date: Re: CreateProcess with as a "Limited User"
- Previous by thread: Re: Limits to memory allocated in DLL
- Next by thread: Re: Limits to memory allocated in DLL
- Index(es):
Relevant Pages
|
Loading