Memory leak???

Started by
6 comments, last by glGreenhorn 22 years, 5 months ago
Hey, I have this small, cute little program. Currently it only draws a couple of lines and initalizes some average-sized structs (a 2D array struct[800][500] which contains a couple of 64bit ints and some smaller values). That''s about all that it declares. No text or anything. At one moment it, however, decided to give me a "not enough memory" warning (heh - that''s no warning - a stupid error it is) and not run at all. Prior to that (when it still bothered to run) it took up ALOT of memory. I have FreeMem trail v installed that shows the amount of available memory in the system tray. Usually it is around 100 megs, but when I ran my prog it dropped to zero . The way I figure it is that even if I did set aside memory for enough stuff to fill ONE HUNDRED megabytes, the program should at least start itself after I rebooted the machine. I''m not sure, but I think I have to declare something somewhere (). Only what and where? Thanks!
Advertisement
Do you declare your 2D array as global or do you allocate it dynamicaly ?
How much information is in your struct? If you have an array of size 800x600 of these things, that''ll eat a lot of memory right there. An 800X600 array of a 64bit data structure would kill 3.8 megs just by itself. 800x600x8bytes=3,840,000. Put a enough data in your struct, and it''ll use all your ram all by itself. What are you trying to do? There''s probably an easier way.

Visit my web site.
"I came, I saw, I coded."
Visit my web site."I came, I saw, I coded."
Do you allocate Mem in your main-loop without freeing it?


Yesterday we still stood at the verge of the abyss,
today we''re a step onward!
Yesterday we still stood at the verge of the abyss,today we're a step onward! Don't klick me!!!
sorry. my mistake. the struct wasn''t a struct, but of type class.
the array is declared as follows:

the header file:

******************************
class N_VECTOR_STRUCT {
UINT START;
UINT LENGTH;
UINT64 LENGTH_MS;
UINT64 START_MS;
UINT START_UUNIT;
CHAR STYLE;
};

extern N_VECTOR_STRUCT VECTOR_STRUCT[500][800];
******************************

source file:
******************************
N_VECTOR_STRUCT N_VECTOR[500][800];
******************************


the declaration is global and there is no memory dynamic allocation.

is the memory allocation for an array of a class similar to that of a struct? sizeof return the size of this class to be 944 bytes which is way too much in my opinion. 64bit int is 8 bytes, right? declaring an array of [10][800] of these takes up about 13 megs of RAM. my claculator can do no more than 7.5 ...

if anyone can suggest a better way to store a potentially large amount of data in a compact form, i''d sure appreciate it....

thanks
i think that a class uses much more space than a struct
try to use a struct
a struct only should use 25byte (a few more)
but thats much less than 900!!

--> trykyn <--
I don''t know what your trying to do with all this data. Must it all be loaded at once? If so, unless you use compression, your our of luck, but since memory is so cheap, buy a few 512MB DIMMS

Also, if you do not use new (or malloc) to allocate your arrray, you are eating up STACK, and [800][500] of int will blow the stack.


Oh yeah, you are using class like a struct in your case...



the size of that structure/class is 32bytes and as the above poster saiz u will need to dynamically allocate memory for it or with 400,000 items youll find it goes *boom* like it has done

This topic is closed to new replies.

Advertisement