memory-allocation

Object pool vs. dynamic allocation

When should one prefer object pool over dynamically allocated objects? I need to create and destroy thousands of objects per second. Is it by itself enough to decide in favor of object pool? Thanks. ...

Object Allocations going crazy.

I have CFArray and CFString allocations going all red while checking on the Instruments Object Alloc. Object seem to be alive but not being used, this because the used part of the histogram is 1/10th of the total histogram (which has turned red) in both cases. the app is a photo library application with 7 view controllers. Loading up ...

iPhone Object Allocation, GeneralBlock-24 & GeneralBlock-48

Hi All, I'm finishing up my third iPhone App. Cleaning up code and such. I have 3 memory leaks after the launch of the application. These remain constant no matter what I do in the App (no more leaks). The issue is that my Net Object Allocation keeps growing up. There are two blocks in particulat, GeneralBlock-24 & GeneralBlock-48 that ...

Callback in C++, template member? (2)

The following callback class is a generic wrapper to "callable things". I really like its API, which has no templates and is very clean, but under the hood there is some dynamic allocation which I was not able to avoid. Is there any way to get rid of the new and delete in the code below while maintaining the semantics and API of the cal...

How is *array* memory allocated and freed in C and C++?

My question specifically is in regards to arrays, not objects. There a few questions on SO about malloc()/free() versus new/delete, but all of them focus on the differences in how they are used. I understand how they are used, but I don't understand what underlying differences cause the differences in usage. I often hear C programmers...

C and C++: Freeing PART of an allocated pointer.

Let's say I have a pointer allocated to hold 4096 bytes. How would one deallocate the last 1024 bytes in C? What about in C++? What if, instead, I wanted to deallocate the first 1024 bytes, and keep the rest (in both languages)? What about deallocating from the middle (it seems to me that this would require splitting it into two poin...

Can AllocHGlobal allocate more the 2GB of memory?

I have resorted to using the Win32 API calls VirtualAlloc/VirtualFree to allocate and release memory blocks greater than 2GB in size. I should be able to use the AllocHGlobal function from the System.Runtime.InteropServices.Marshal class to do the same. However, the following code gives an arithmetic overflow exception (note the explic...

PHP: Manipulate a string that that is 30 mil chars long?

I am downloading a CSV file from another server as a data-feed from a vendor. I am using curl to get the contents of the file and saving that into a variable called $contents. I can get to that part just fine, but I tried exploding by (both "\r" and "\n") to get an array of each line but it tells me "the fatal error, memory allocation"...

C memory space and #defines

I am working on an embedded system, so memory is precious for me. One issue that has been recurring is that I've been running out of memory space when attempting to compile a program for it. This is usually fixed by limiting the number of typedefs, etc that can take up a lot of space. There is a macro generator that I use to create a ...

In java Can objects be created with both static memory allocation and dynamic memory allocation?

In java Can objects be created with both static memory allocation and dynamic memory allocation? ...

Perl memory usage profiling and leak detection?

I wrote a persistent network service in Perl that runs on Linux. Unfortunately, as it runs, its Resident Stack Size (RSS) just grows, and grows, and grows, slowly but surely. This is despite diligent efforts on my part to expunge all unneeded hash keys and delete all references to objects that would otherwise cause reference counts...

In Objective-C, how does +alloc know how much memory to allocate?

Let's say I have a class declared as: @class SomeClass @interface SomeClass: NSObject { NSString *myString; NSString *yourString; } @end And later, in some other code I say: SomeClass *myClass = [[SomeClass alloc] init]; How does SomeClass know how much memory to allocate given that it didn't override +alloc? Presumably it n...

Is there ever a need for a class to override +alloc in Objective-C?

Based on some answers to this question it appears that +alloc does some behind-the-scenes magic to allocate memory for an instance of an object in Objective-C. Is there ever a need to override +alloc? ...

How does it know where my value is in memory?

When I write a program and tell it int c=5, it puts the value 5 into a little bit of it's memory, but how does it remember which one? The only way I could think of would be to have another bit of memory to tell it, but then it would have to remember where it kept that as well, so how does it remember where everything is? ...

Defining String Literals?

Can anyone confirm this for me ... NSString *testString = @"Betty"; By my way of thinking this line is declaring the NSString pointer (*testString) to point to the string literal @"Betty". This declaration does not need an alloc, nor does it need to be released? I just want to make sure I am on the right track. -gary- ...

C++ dynamically allocated array of statically dimensioned arrays

I need to create a structure that holds a variable number of 'char[2]'s, i.e. static arrays of 2 chars. My question is, how do I allocate memory for x number of char[2]. I tried this (assuming int x is defined): char** m = NULL; m = new char[x][2]; ... delete [] m; (it didn't work) I realise I could use std::vector<char[2]> as a co...

Does calling free or delete ever release memory back to the "system"

Hi Here's my question : Does calling free or delete ever release memory back to the "system". By system I mean, does it ever reduce the data segment of the process ? Lets consider the memory allocator on Linux, i.e ptmalloc. From what I know(please correct me if I am wrong), ptmalloc maintains a free list of memory blocks and when a ...

iPhone development: pointer being freed was not allocated

Hello, i got this message from the debugger: Pixture(1257,0xa0610500) malloc: *** error for object 0x21a8000: pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug so i did a bit of tracing and got: (gdb) shell malloc_history 1257 0x21a8000 ALLOC 0x2196a00-0x21a89ff [size=73728]: thread_a0...

SQL database interaction

Hello everyone, I am making a database, which will interact with a SQL table. What I have achieved so far: Add rows to the table. Delete rows from the table. Search rows from the table. Paginate the results. What I need to achieve: A log in prompt when a guest tries to access the page. In fact, I have successfully installed a ...

relloc behavior on resize

How does relloc behaves when it has to resize the allocated memory to a bigger size and it has to be done in a separate memory area as the requested amount of memory can be resized inplace. Does the original memory is deallocated automatically by relloc (I would think so ) or it has to be done by the programmer (not likely) ? ...