allocation

Returning stack data in C; Does it unallocate correctly?

I was reviewing a friend's code and got into an interesting debate on how C/C++ allocates memory on the stack and manages its release. If I were to create an array of 10 objects in a function, but return said array, does it release when the function pops (hence making the given data invalid) or is it placed into the heap (which raises th...

Android: Track number of objects created

I'm porting a game to Android (there's a lot of code and very little of it is mine), and DalvikVM is telling me (through LogCat) all about the garbage collection. At some point in the code, I get a stream of "GC freed x objects / x ms" messages, basically informing me that ~150,000 objects have just been deleted and it's taking a full se...

Why this code doesn't allocate memory in C?

Updated question is here http://stackoverflow.com/questions/828108/please-help-me-to-solve-this-memory-allocation-problem I'm working on making a HashTable in C. This is what I've done. I think I'm going on a right path but when I'm trying to main.c HashTablePtr hash; hash = createHashTable(10); insert(hash, "hello"); insert(hash, "...

Are cross-dll allocations ok?

If I have an app that uses at least two dlls, is it generally safe to allocate resources in one dll and free them in another? I'm thinking specifically about calling fopen and fclose in different dlls, but I'd also like to know that it's safe for other resources (memory pointers, handles, etc...). I think as long as everything is compi...

Allocation of managed objects in Managed C++

Is it necessary to check for nullptr after allocating an object using gcnew? ...

Possible NP-complete problem?

I'd just like someone to verify whether the following problem is NP-complete or if there is actually a better/easier solution to it than simple brute-force combination checking. We have a sort-of resource allocation problem in our software, and I'll explain it with an example. Let's say we need 4 people to be at work during the day-shi...

iphone sqlite3 object allocation memory up but no leaks

Hi All, i've been trying to figure out wh. sqy my object allocation keeps rigth up every time i call this function, Instruments reports no leaks but I get a heck of a lot of object coming from sqlite3_exec --> sqlite3Prepare --> sqlite3Parser --> yy_reduce --> malloc & also a whole bunch from & from sqlite3Step --> sqlite3VdbeExec...

Why is alloca not considered good practice?

Alloca allocates memory from Stack rather then heap which is case in malloc. So, when I return from the routine the memory is freed. So, actually this solves my problem of freeing up of dynamically allocated memory . Freeing of memory allocated through malloc is a major headache and if somehow missed leads to all sorts memory problems. ...

Why isn't my new operator called

I wanted to see that a dynamically loaded library (loaded with dlopen etc.) really uses its own new an delete operators and not these ones defined in the calling program. So I wrote the following library.cpp #include <exception> #include <new> #include <cstdlib> #include <cstdio> #include "base.hpp" void* operator new(size_t size) { st...

c++ memory allocation question

im trying to create an array: int HR[32487834]; doesn't this only take up about 128 - 130 megabytes of memory? im using MS c++ visual studios 2005 SP1 and it crashes and tells me stack overflow. ...

Given an Array, is there an algorithm that can allocate memory out of it?

Hi, I'm doing some graphics programming and I'm using Vertex pools. I'd like to be able to allocate a range out of the pool and use this for drawing. Whats different from the solution I need than from a C allocator is that I never call malloc. Instead I preallocate the array and then need an object that wraps that up and keeps track of ...

determine size of dynamically allocated memory in c

Is there a way in c to find out the size of dynamically allocated memory? For e.g., Suppose I say char* p = malloc(sizeof(char)*100); Now is there a way to find out the size of memory associated with p? ...

Java memory allocation performance (SunOS vs Windows)

I have a very simple unit test that just allocates a lot of Strings: public class AllocationSpeedTest extends TestCase { public void testAllocation() throws Exception { for (int i = 0; i < 1000; i++) { long startTime = System.currentTimeMillis(); String a = "dummy"; for (int j = 0; j < 1000; j++) { a ...

How to determine allocated blocks on an NTFS disk

Is there a way of determining which clusters on an NTFS disk are allocated? I'm thinking along the lines of the display you see on a defrag program before you kick off the defrag itself. I guess you could parse the MFT but it strikes me that this could take a long time on a system with potentially hundreds of thousands of files. Thanks...

C dynamic allocation for a grid when rows are not known

I am trying to allocate a array of char*'s in C. I know the number of columns in advance, but not the rows and I want to allocate the rows as and when needed. I tried to use: char *(*data)[NUMCOLS]; //declare data as pointer to array NUMCOLS of pointer to char data = malloc(sizeof(char*)); now, the above line should allocate for dat...

Proof that Fowler's money allocation algorithm is correct.

Martin Fowler has a Money class that has a money allocation routine. This routine allocates money according to a given list of ratios without losing any value through rounding. It spreads any remainder value over the results. For example, $100 allocated by the "ratios" (1, 1, 1) would yield ($34, $33, $33). Here is the allocate functio...

Custom malloc() implementation header design

I am trying to write a custom allocator for debugging purposes (as an exercise) in C, where I will be using a single linked list to hold together the free list of memory using the First Fit Algorithm. I've shown below the structure I would like to create in an "Empty Memory Node". How do I write the header block (a union to be specific)...

iPhone application lags after launching and dismissing MFMailComposeViewController

Hello, I have an application that uses a table view controller to display some items, after clicking on one of those items you may select to email this item. Once that happens I use the code provided by apple "MailComposer", and send the mail. However after this the scrolling in the table view is not as smooth as before. I checked wit...

Allocation latency seems high, why?

I have a (java) application that runs in a low latency environment, it typically processes instructions in ~600micros (+/- 100). Naturally as we've moved further into the microsecond space the things you see that cost latency change and right now we've noticed that 2/3 of that time is spent in the allocation of the 2 core domain objects...

How can I schedule some code to run after all '_atexit()' functions are completed

I'm writing a memory tracking system and the only problem I've actually run into is that when the application exits, any static/global classes that didn't allocate in their constructor, but are deallocating in their deconstructor are deallocating after my memory tracking stuff has reported the allocated data as a leak. As far as I can t...