473,574 Members | 2,971 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4063
Pete <ps*@usa.com> wrote in message news:4wg_a.1309 97$Ho3.16611@sc crnsc03...
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
"optimizati on" 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.provi ded> wrote in message
news:PV******** ********@nasal. pacific.net.au. ..
Pete <ps*@usa.com> wrote in message news:4wg_a.1309 97$Ho3.16611@sc crnsc03...
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
16673
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 (root@Pentium.suse.de) (gcc version 3.3 20030226 (prerelease) (SuSE Linux)) #1 Wed Aug 6 18:26:21 UTC 2003 Apache 1.3.27-41 PHP 4.3.1-52 MySQL 3.23.55-20
5
6067
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 loss even though I seem to be allocaitng everything; help would be *vastly* appreciated. What am I doing wrong here? I thought I was doing...
5
1998
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 memory to load next image I remove first ones from the cache. But I have a lot of problems with memory. A lot of time when I just ask for memory, a...
7
4960
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 applications, the db2syscs.exe process started gobbling up memory until it hit about 1.7 gigs (which seems to be the limit from what I've read) then it...
10
14034
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 file to use purify. However, my code is a rather simple single-source C program, and I didn't write a Makefile for it. I'm wondering if anybody...
18
3294
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 ******************************************** /* mallocm.c */ /* funzione di libreria per trattamento della memoria e rilevamento errori */ /* uso: c_compiler malloc.c e...
21
2926
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 updated this system and changed the pages that are saved to the server as aspx - everything works fine and pages can be served - but Its not...
2
3258
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 and arrays of pointers to them. I have gotten the program to compile with gcc on WinXP. If the file i read doesnt have alot of records, it runs...
9
9217
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 website. The problem is: it's eating more memory than a black hole. It eats the current limit of 256MB set in php.ini, in an application that would...
13
2842
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. It's most possibly caused by trac and it's dependencies, but several components of the OS where updated, too.
0
7805
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7726
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8053
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8237
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7817
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5301
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3741
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2245
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1341
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.