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 2 4075
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
|
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 everything correctly (setting things to
null, for example) but none of the memory seems to get replaced. ...
|
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 big chunk of memory though, like for example 200 Mo the
|
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
started crapping out.. We have shrunk the buffer pools to much lower
that they used to be in 7,...
|
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 can tell me which commands are to be
entered at the Unix prompt to use purify. And, I don't know if...
| |
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 usare malloc .obj */
|
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 impossible for a single client to request 100 plus pages in one
session - as each page is requested it is...
|
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 thru. But once
i add more, it dies. In this program i have 4 files setup to read. The
|
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 hardly
consume 4MB if written in C. I don't care if this application takes much longer
to run...
|
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.
|
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 usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
| |
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |