Archived

This topic is now archived and is closed to further replies.

glGreenhorn

Memory leak???

Recommended Posts

glGreenhorn    122
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!

Share this post


Link to post
Share on other sites
AEBergen1980    122
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."

Share this post


Link to post
Share on other sites
glGreenhorn    122
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

Share this post


Link to post
Share on other sites
trykyn    122
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!!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
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...



Share this post


Link to post
Share on other sites
zedzeek    529
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

Share this post


Link to post
Share on other sites