memory-management

C++'s "placement new"

Has anyone here ever used C++'s "placement new"? If so, what for? It looks to me like it would only be useful on memory-mapped hardware. ...

Solve the memory alignment in C interview question that stumped me

I just finished a test as part of a job interview, and one question stumped me - even using google for reference. I'd like to see what the stackoverflow crew can do with it: The “memset_16aligned” function requires a 16byte aligned pointer passed to it, or it will crash. a) How would you allocate 1024 bytes of memory, and align it to a...

Efficient heap-manager for heavy churn, tiny allocs?

I'm looking for ideas for a heap-manager to handle a very specific situation: Lots and lots of very small allocations, ranging from 12 to 64 bytes each. Anything bigger, I will pass on to the regular heap-manager, so only tiny blocks need be catered for. Only 4-byte alignment is needed. My main concerns are Overhead. The regular libc ...

How can I get the size of an array from a pointer in C?

I've allocated an "array" of mystruct of size n like this: if (NULL == (p = calloc(sizeof(struct mystruct) * n,1))) { /* handle error */ } Later on, I only have access to p, and no longer have n. Is there a way to determine the length of the array given just the pointer p? I figure it must be possible, since free(p) does just that. ...

UNIX vs Windows memory deallocation

My understanding is that in unix, when memory is freed, the memory doesn't get returned back to the operating system, it stays in the process to be used again for the next call to malloc. On windows, I understand that the memory actually gets returned to the operating system. Is there any big difference between these two ways of doing ...

How to interpret the memory usage figures?

Can someone explain this in a practical way? Sample represents usage for one, low-traffic Rails site using Nginx and 3 Mongrel clusters. I ask because I am aiming to learn about page caching, wondering if these figures have significant meaning to that process. Thank you. Great site! me@vps:~$ free -m total u...

Freeing memory on the heap. Should I and how?

I'm writing a CESetup.dll for a Windows Mobile app. It must be unmanaged, which I have little experience with. So I'm unsure of whether I should free the memory I allocate and how I do it. Here's the function I've written: Uninstall_Init( HWND hwndParent, LPCTSTR pszInstallDir ) { LPTSTR folderPath = new TCHA...

What is the difference between new/delete and malloc/free?

What is the difference between new/delete and malloc/free? Related (duplicate?): In what cases do I use malloc vs new? ...

How can I tell if my managed code is leaking memory due to native library calls?

I have a managed dll that calls into a native library. This native library generally returns IntPtrs. These can be passed in to other methods in the native library to do things, or to tell the library to free the instance associated with the IntPtr. But only some of the instances need to freed in this way, others are managed by the li...

NSThread with _NSAutoreleaseNoPool error

I have an method which save files to the internet, it works but just slow. Then I'd like to make the user interface more smooth, so I create an NSThread to handle the slow task. I am seeing a list of errors like: _NSAutoreleaseNoPool(): Object 0x18a140 of class NSCFString autoreleased with no pool in place - just leaking Without NST...

How do I memory manage UIViewControllers with a navigation controller?

So yeah, I'm a Java guy in this crazy iPhone world. When it comes to memory management I stiill don't have a very good idea of what I'm doing. I have an app that uses a navigation controller, and when it's time to go on to the next view I have code that looks like this: UIViewController *myController = [[MyViewController alloc] initWi...

C++: dynamically allocating an array of objects?

This is kind of a beginners question, but I haven't done C++ in a long time, so here goes... I have a class that contains a dynamically allocated array, say class A { int* myArray; A() { myArray = 0; } A(int size) { myArray = new int[size]; } ~A() { // Note that as per MikeB's...

Tools to visually analyze memory usage of a PHP app.

Is there anything out there freeware or commercial that can facilitate analysis of memory usage by a PHP application? I know xdebug can produce trace files that shows memory usage by function call but without a graphical tool the data is hard to interpret. Ideally I would like to be able to view not only total memory usage but also wh...

Is it worth caching objects created by Delphi's Memory Manager?

I have an application that creates, and destroys thousands of objects. Is it worth caching and reusing objects, or is Delphi's memory manager fast enough that creating and destroying objects multiple times is not that great an overhead (as opposed to keeping track of a cache) When I say worth it, of course I'm looking for a performance b...

Why does Delphi's memory manager report false memory leaks at shutdown?

I'm getting the memory leak message upon shutdown, saying that I'm leaking 3 of a certain object. Two problems with that, though. It only happens intermittently. I can run my program, go through the exact same series of steps, (open a data file, display it, and shut down again,) and sometimes the message will show up and sometimes it...

Create a wrapper function for malloc and free in C

Hey, I am trying to create wrapper functions for free and malloc in C to help notify me of memory leaks. Does anyone know how to declare these functions so when I call malloc() and free() it will call my custom functions and not the standards lib functions? ...

Dynamic memory allocation in VB6

Is there such a thing? I'm talking about something like a C++ new command i.e. allocation of memory which necessitates explicit releasing of the memory (or risk memory leaks). I ask because I remember having to solve some GDI leak problems previously by setting forms/controls/other objects to Nothing but can't remember what or why now...

Kernel Memory Management - Page Handling Design

I'm working on kernel design, and I've got some questions concerning paging. The basic idea that I have so far is this: Each program gets its own (or so it thinks) 4G of memory, minus a section somewhere that I reserve for kernel functions that the program can call. So, the OS needs to figure out some way to load the pages in memory tha...

Singleton Destructors

Should Singleton objects that don't use instance/reference counters be considered memory leaks in C++? Without a counter that calls for explicit deletion of the singleton instance when the count is zero, how does the object get deleted? Is it cleaned up by the OS when the application is terminated? What if that Singleton had allocated...

Does the List Clear() method destroy children [C#.NET]?

If I create a recursive list of of lists: class myList { List<myList> childLists; List<string> things; //... } List<myList> tempList = new List<myList>(); And then later call tempList.Clear(), will it destroy all the childLists in memory, or should I create a recursive method to clear all the childLists first? ...