Re: Newbie: out of memory issues
* Scott McPhillips [MVP]:
<trx32@mchsi.com> wrote in message
news:ncmpa455lbp8rq3pn9hj4is7sdi6n43mq8@4ax.com...
Hi,
Please forgive the "newbie" question but:
My MFC program is coming a long ok, but when I ran it lately I'm
getting "out of memory" issues on one of the procedures.
My background is more vb.net.
What kinds of things do I need to learn/be more aware/to look out for
in order to stay on top of these kinds of issues?
What topics in C++ do I need to review to understand what is going
on?
It would help if you tell us how you are allocating large amounts of
memory in that procedure. The most common problem is allocating
something on the stack that is too big for the stack:
void function()
{ int a[400000000]; // stack allocation
}
In such cases you have a better chance of getting the memory if you
allocate it from the heap instead:
int* pa = new int[400000000]; // heap alloction
To someone ignorant enough to do the hundreds-of-megs-on-stack thing, it's not a
good idea to recommend dynamically allocated array referred by raw pointer.
It's like handing a running chainsaw to a child complaining about lack of
progress in sawing through a small piece of wood manually: it's the wrong tool
for the job no matter who wields it, and it's certainly not a tool that's
suitable for a child -- although a child might think so.
Instead e.g.
std::vector<int> a( 400000000 );
Cheers, & hth.,
- Alf
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?