473,385 Members | 1,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

memory problems

I've run into an interesting memory problem. I think I'm running out of
heap space, but I'm not sure....

I'm creating two new arrays like such....

pImage = new UBYTE [nImageSize];
pImageTemp = new UBYTE [nImageSize];

where nImageSize = 262144. new is NOT returning NULL at this point, which
gives me the impression that new succeeded.

After a little error checking, the code goes to the following statement....

for(int tries = 0;tries <10 && fread (pImageTemp, sizeof (UBYTE),
nImageSize, pFile) != nImageSize; tries++)
{
fclose (pFile);
if (tries == 9)
{
delete [] pImage;
delete [] pImageTemp;
return 0;
}

Now given a pFile named "cloak.tga" (which BTW, was opened succesfully),
this code will successfully load "cloak.tga" most of the time. However, at
an arbitrary point ( say the 4th or 5th time I call this code) fread will
fail. Once it fails it enters the above loop to try freading 9 more times.
Once it fails the first time it will ALWAYS fail the next 9 times. At this
point, when

delete [] pImageTemp;

is called, I get the following error message:

HEAP[Bruteball.exe]: Heap block at 070ADB18 modified at 070ADF50
past requested size of 430

So am I running out of Heap space? If so, why isn't new returning NULL?
Anyone have any ideas of how to fix this issue?

Thanks,
-Pete
Jul 19 '05 #1
2 4046
Pete <ps*@usa.com> wrote in message news:4wg_a.130997$Ho3.16611@sccrnsc03...
I've run into an interesting memory problem. I think I'm running out of
heap space, but I'm not sure....

I'm creating two new arrays like such....

pImage = new UBYTE [nImageSize];
pImageTemp = new UBYTE [nImageSize];

where nImageSize = 262144. new is NOT returning NULL at this point, which gives me the impression that new succeeded.

After a little error checking, the code goes to the following statement....
for(int tries = 0;tries <10 && fread (pImageTemp, sizeof (UBYTE),
nImageSize, pFile) != nImageSize; tries++)
{
fclose (pFile);
if (tries == 9)
{
delete [] pImage;
delete [] pImageTemp;
return 0;
}

Now given a pFile named "cloak.tga" (which BTW, was opened succesfully),
this code will successfully load "cloak.tga" most of the time. However, at an arbitrary point ( say the 4th or 5th time I call this code) fread will
fail. Once it fails it enters the above loop to try freading 9 more times.
Once it fails the first time it will ALWAYS fail the next 9 times.
But you are closing the file in the loop, so it has to fail every other
time.
At this
point, when

delete [] pImageTemp;

is called, I get the following error message:

HEAP[Bruteball.exe]: Heap block at 070ADB18 modified at 070ADF50
past requested size of 430

So am I running out of Heap space? If so, why isn't new returning NULL?
Unless it's an old compiler it will never return null. 'new' throws an
exception if it fails, so if it returns at all it succeeded.
Anyone have any ideas of how to fix this issue?
I don't think you are running out of memory. It looks like a memory
corruption caused by writing to where you are not supposed to. I can't tell
from the code you've posted what's wrong. Try deleting the memory
immediately after allocating it and see if the error still occurs. If it
doesn't then you know you are doing something later that's causing the
corruption. If you post the code for a complete, small-as-possible program
that exhibits the problem then the cause of the problem might be more
apparent.

Thanks,


Thank you. I'm sure many regulars are relieved and grateful for your
on-topic question.

DW

Jul 19 '05 #2
LOL! Good point about the fclose(). I just added that retry loop last
minute to try and debug. Course if your debugging code has a bug in it, its
not that useful, LOL!

Thanks for the feedback. I managed to figure out what was wrong. This code
is used to colorize and overlay a bunch of grayscale tga files into the same
memory chunk, so that a single openGL texture can be created out of about
15 overlaped tga files. Its for a random anime face generator. Turns out
at some point I got the brilliant idea to save space by turning a couple all
ALPHA tga files (bald guys) into 16x16, in my 256x256 image directory. Of
course trying to fit a 256x256 image in the space of a 16x16 image
apparently causes some problems ;) Funny thing is I didn't make the same
"optimization" in my 64x64 image dirrectory, so I wasn't having a problem
with the smaller images. LOL! I'm a moron.

Thanks again for the feedback.

-Pete

"David White" <no@email.provided> wrote in message
news:PV****************@nasal.pacific.net.au...
Pete <ps*@usa.com> wrote in message news:4wg_a.130997$Ho3.16611@sccrnsc03...
I've run into an interesting memory problem. I think I'm running out of
heap space, but I'm not sure....

I'm creating two new arrays like such....

pImage = new UBYTE [nImageSize];
pImageTemp = new UBYTE [nImageSize];

where nImageSize = 262144. new is NOT returning NULL at this point,

which
gives me the impression that new succeeded.

After a little error checking, the code goes to the following

statement....

for(int tries = 0;tries <10 && fread (pImageTemp, sizeof (UBYTE),
nImageSize, pFile) != nImageSize; tries++)
{
fclose (pFile);
if (tries == 9)
{
delete [] pImage;
delete [] pImageTemp;
return 0;
}

Now given a pFile named "cloak.tga" (which BTW, was opened succesfully),
this code will successfully load "cloak.tga" most of the time. However,

at
an arbitrary point ( say the 4th or 5th time I call this code) fread will fail. Once it fails it enters the above loop to try freading 9 more

times.

Once it fails the first time it will ALWAYS fail the next 9 times.


But you are closing the file in the loop, so it has to fail every other
time.
At this
point, when

delete [] pImageTemp;

is called, I get the following error message:

HEAP[Bruteball.exe]: Heap block at 070ADB18 modified at 070ADF50
past requested size of 430

So am I running out of Heap space? If so, why isn't new returning

NULL?
Unless it's an old compiler it will never return null. 'new' throws an
exception if it fails, so if it returns at all it succeeded.
Anyone have any ideas of how to fix this issue?
I don't think you are running out of memory. It looks like a memory
corruption caused by writing to where you are not supposed to. I can't

tell from the code you've posted what's wrong. Try deleting the memory
immediately after allocating it and see if the error still occurs. If it
doesn't then you know you are doing something later that's causing the
corruption. If you post the code for a complete, small-as-possible program
that exhibits the problem then the cause of the problem might be more
apparent.

Thanks,


Thank you. I'm sure many regulars are relieved and grateful for your
on-topic question.

DW

Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Maurice | last post by:
Hi there, I'm experiencing big memory problems on my webserver. First on an old RedHat 7.2 system, now on an other fresh installed Suse 8.2 system: Linux version 2.4.20-4GB...
5
by: Justice | last post by:
Currently I'm doing some experimenting with the XMLHTTP object in Javascript. Now, the XMLHttp object is asynchronous (at least in this case), and the following code causes a significant memory...
5
by: DLPnet | last post by:
Hello, I m working on Windows and Mac in C++. My application uses a lot of memory since it s dealing with a lot of images. So I load images in a cache when needed and if I haven t enough...
7
by: Jon Trickey | last post by:
We migrated to 8.1 from 7.2 this weekend. Everything ran ok over the weekend, but we have a light user load then (about 200 users.) Today when we had close to 600 users connecting and running...
10
by: eyh5 | last post by:
Hi, My C code (running on Soalris Unix) has some "segmentation fault" that I wish to use purify to do it. I poked around the web, and found some information about adding some lines in a Makefile...
18
by: cs | last post by:
This is the function malloc_m() that should be like malloc() but it should find memory leak, and over bound writing in arrays. How many errors do you see? Thank you...
21
by: matvdl | last post by:
I have a system that was originally developed in asp - the pages are saved in SQL (there are over 10,000 pages) and saved to a temp directory in the server when requested by a client. I have...
2
by: Mike | last post by:
Hi, I am new to C and having problems with the following program. Basically I am trying to read some files, loading data structures into memory for latter searching. I am trying to use structres...
9
by: Bruno Barberi Gnecco | last post by:
I'm using PHP to run a CLI application. It's a script run by cron that parses some HTML files (with DOM XML), and I ended up using PHP to integrate with the rest of the code that already runs the...
13
by: Ilias Lazaridis | last post by:
How to detect memory leaks of python programms, which run in an environment like this: * Suse Linux 9.3 * Apache * mod_python The problem occoured after some updates on the infrastructure....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.