memory-management

Should a list of objects be stored on the heap or stack?

I have an object(A) which has a list composed of objects (B). The objects in the list(B) are pointers, but should the list itself be a pointer? I'm migrating from Java to C++ and still haven't gotten fully accustomed to the stack/heap. The list will not be passed outside of class A, only the elements in the list. Is it good practice to a...

Direct Memory Access in Linux

I'm trying to access physical memory directly for an embedded Linux project, but I'm not sure how I can best designate memory for my use. If I boot my device regularly, and access /dev/mem, I can easily read and write to just about anywhere I want. However, in this, I'm accessing memory that can easily be allocated to any process; which...

stack & realloc question C++

int main() { char myString = NULL; realloc(&myString, 5); strncpy((char *)&myString, "test", 5); } Seems to work Fine but, i'm still slightly confused about stack vs heap, is this allowed? Does myString need to be freed manually or will it be released when it goes out of scope? Edit: Thanks for the responses, so i presume t...

Is this scenario suitable for WeakReferences ?

I am working on querying the address book via J2ME and returning a custom Hashtable which I will call pimList. The keys in pimList {firstname, lastname} maps to an object (we'll call this object ContactInfo) holding (key, value) pairs e.g. work1 -> 44232454545, home1 -> 44876887787 Next I take firstName and add it into a tree. The node...

NSNumber retain count issue

NSNumber* n = [[NSNumber alloc] initWithInt:100]; NSNumber* n1 = n; In the code above, why is the value of n's retainCount set to 2? In the second line of the code, I didn't use retain to increase the number of retainCount. I found a strange situation. actually the retainCount set to 2 is not related to the assignment of second line...

C++ Memory Management for Texture Streaming in Videogames

Hi, this is a "hard" question. I've found nothing interesting over the web. I'm developing a Memory Management module for my company. We develop games for next-gen consoles (Xbox 360, PS3 and PC... we consider PC a console!). We'll need in future, for our next games, to handle texture streaming for large game worlds that cannot be load...

Memory usage of a kernel module

While trying to estimate the amount of memory consumed by a kernel module (usually device drivers),I tried using the size utility which gave the size of the static memory areas of the .ko ( .bss, .data, .text etc). So I was expecting the sum of these values to be exactly equal to the output given by the lsmod command immediately after in...

Does [NSMutableDictionary setValue: value forKey: key] retain NSString key?

When adding items to NSMutableDictionary using the setValue:forKey: method (I suppose this generalizes to any NSObject) does the dictionary retain the second parameter, the NSString? For example: NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; NSString *theStri...

iPhone memory management question (adding a subview to a view in a for statement)

I need to add more views to a view for handling multiple webaddress and the clicks on the labels. I try to do it in a for statement. My code is something like that: // we have a UITabbarViewController for holding amongs other the parentViewController UITabBarController *tabbedViewController = [[UITabBarController alloc] init]; // creat...

How to deallocate memory when a Qt window closes?

I am currently creating a program in Qt, OpenCv, Mac os X. I have a main window, and then a separate window that is opened. I pass the new window several matrix clones in the constructor: ImageWindow *imageWin = new ImageWindow( cvCloneMat(getData->getMasterRawMat(1)), cvCloneMat(getData->getMasterRawMat(2)), cvCloneMat(get...

How is dynamic memory managed in std::vector?

How does std::vector implement the management of the changing number of elements: Does it use realloc() function, or does it use a linked list? Thanks. ...

VB6 Memory Leak

Can a VB6 program that does not contain the keyword 'New' have memory leaks? If so, please provide an example. ...

JVM sending back memory to OS

Hi all, I have a question regarding the JVM memory management (at least for the SUN's one). I would like to know how to control the fact that the JVM send the unused memory back to the OS (windows in my case). I wrote a simple java program to illustrate what I expect. Run it with -Dcom.sun.management.jmxremote option so that you can a...

Seg fault after is item pushed onto STL container

typedef struct temp { int a,b; char *c; temp(){ c = (char*)malloc(10);}; ~temp(){free(c);}; }temp; int main() { temp a; list<temp> l1; l1.push_back(a); l1.clear(); return 0; } giving segmentation fault. ...

Memory management while loading huge XML files

We have an application which imports objects from an XML. The XML is around 15 GB. The application invariably starts running out of memory. We tried to free memory in between operations but this has lead to degrading performance. i.e it takes more time to complete the import operation. The CPU utilization reaches 100% The application is...

.net Out of Memory exceptions in Windows Mobile - how to overcome this problem?

I am currently writing a small application in Windows Mobile using CF.NET. The application is very similar in its behaviour to an e-mail application i.e. I am using POP3 to download messages and attachments from my mail-server account to store on the storage-card for further processing with a MIME-tool. My problem is downloading large ...

Object Pooling

What are the pro's and con's of maintaining a pool of frequently used objects and grab one from the pool instead of creating a new one. Something like string interning except that it will be possible for all class objects. For example it can be considered to be good since it saves gc time and object creation time. On the other hand it c...

About C/C++ stack allocation

While studying C++ (and C) I had some particular doubts regarding the working of stack allocation, that I can't find a solution to: Does stack allocation call malloc/free functions implicitly? If not; how does it assure there is no conflict between stack allocation and heap allocation? If yes; does stack allocation in C++ implicitly ca...

Large Object Heap Fragmentation

The C#/.NET application I am working on is suffering from a slow memory leak. I have used CDB with SOS to try to determine what is happening but the data does not seem to make any sense so I was hoping one of you may have experienced this before. The application is running on the 64 bit framework. It is continuously calculating and se...

Re-assinging an "auto_ptr" and Managing Memory

I've a situation like this: class MyClass { private: std::auto_ptr<MyOtherClass> obj; public: MyClass() { obj = auto_ptr<MyOtherClass>(new MyOtherClass()); } void reassignMyOtherClass() { // ... do funny stuff MyOtherClass new_other_class = new MyOtherClass(); // Here, I want to: // 1) Delete the point...