allocation

Allocation algorithm help, using Python.

Hi there, I've been working on this general allocation algorithm for students. The pseudocode for it (a Python implementation) is: for a student in a dictionary of students: for student preference in a set of preferences (ordered from 1 to 10): let temp_project be the first preferred project check if temp_project...

Recycle Freed Objects

suppose I need to allocate and delete object on heap frequently (of arbitrary size), is there any performance benefit if instead of deleting those objects, I will return it back to some "pool" to be reused later? would it give benefit by reduce heap allocation/deallocation?, or it will be slower compared to memory allocator performance,...

Memory ReAllocation

What is the right and best way to reallocate memory? for example I allocate 100 bytes with WinAPI function HeapAlloc then I fill 100 bytes of that memory with some data and now I want to add more new data at end of previous... What Should I do? Make a new allocation with more bytes and then copy old+new to new location and free old memo...

Efficient algorithm for creating an ideal distribution of groups into containers with potential overflow?

I have groups of students that need to be allocated into classrooms of a fixed capacity (say, 100 chairs in each). Each group must only be allocated to a single classroom, even if it is larger than the capacity (ie there can be an overflow, with students standing up) I need an algorithm to make the allocations with minimum overflows an...

Boost::Mutex & Malloc

Hi all, I'm trying to use a faster memory allocator in C++. I can't use Hoard due to licensing / cost. I was using NEDMalloc in a single threaded setting and got excellent performance, but I'm wondering if I should switch to something else -- as I understand things, NEDMalloc is just a replacement for C-based malloc() & free(), not th...

What do I do if constructor fails to allocate memory in C++?

I just came across a problem where the constructor of a class needs to allocate memory. So I happily wrote char *mem = static_cast<char*>(malloc(100*sizeof(*mem)));. But then I suddenly realized that in case of error I can't return error code (I am not using exceptions in my code). How can I solve this problem? Should I add an bool init...

What is the better way of handling temporary strings?

I have a situation where I need to use some strings temporarily but I've read so many conflicting things that I'm a bit confused as to what the best way to proceed is. I need to assign some strings inside an if structure but use them outside the if structure so they need to be created outside the if, I was thinking something like: NSSt...

C++: What does it mean to "new" a collection that will keep growing?

Hi all, I am new to C++. What does it mean exactly to "new" a collection? For example: UnicodeStringList* tmp = new UnicodeStringList; // where UnicodeStringList is typedef to std::list<UnicodeString> When you "new" something you have to know exactly how big you need it to be, right? So when I use the assignment constructor to c...

Freeing dynamically allocated memory

In C++, when you make a new variable on the heap like this: int* a = new int; you can tell C++ to reclaim the memory by using delete like this: delete a; However, when your program closes, does it automatically free the memory that was allocated with new? ...

Resource Allocation Graph with Deadlock

I am doing project in computer science, and i came know the term 7-process resource allocation graph with deadlocks. I wonder how does it look because i dont know anything about deadlocks. ...

Java memory allocation on stack vs heap

I feel like a novice for asking this question -- but why is it that when I pass the Set below into my method and point it to a new HashSet, it still comes out as the EmptySet? Is it because local variables are allocated on the stack, and so my new is blown away when I exit the method? How could I achieve the functional equivalent? imp...

iPhone memory leak (a lot of allocations)

I tested my app in Instruments. No leaks found, but app crashes (not immediately - after ~20 minutes [depends on user's activity] of working). I viewed Allocations. It reports: Category | Live Bytes | Count Live | # Living | # Transitory | Overall Bytes | # Allocations (Net / Overall) Malloc 16 Bytes | 235088 | 14693 | 0 | 235088 | 1469...

A very basic question about alloc and release

Hi Forum I'm a little confused about objc and allocating/releasing objects. If I do this: NSString *myString; if([someString isEqualToString: @"test1"]){ myString = @"got 1"; }else{ myString = @"got 2"; } Do I have to release myString after that? And the same with self-defined objects: myOwnObject *someObject = [someArray...

How to avoid long chain of free's (or deletes) after every error check in C?

Suppose I write my code very defensively and always check the return types from all the functions that I call. So I go like: char* function() { char* mem = get_memory(100); // first allocation if (!mem) return NULL; struct binder* b = get_binder('regular binder'); // second allocation if (!b) { free(mem); ...

Calling alloc on a pointer

I'm using cocos2d with objective C. I have a class called CrystalineBubble that is currently empty it inherits from CCNode. #import <Foundation/Foundation.h> #import "cocos2d.h" @interface CrystalineBubble : CCNode { } @end When I try to create an instance of that class and alloc it I get the warning 'CrystalineBubble' may not ...

Storing a char in a char pointer

I have a global variable that is a *char. My main function header reads as int main(int argc, char* argv[argc]){...}. These two lines of code have to remain the way they are. The first argument of my main function is a number of type *char, that I convert to a char using atoi(...);. I am basically changing the ASCII value to its corresp...

Trying to free allocated memory borrowed when initializing an object, but getting Xcode warning

OK, so I have my main.m program code, and mvds suggested I free the allocated memory I borrowed from my class when I created a new instance. For some reason, when I attempt to free the memory using [converter free]; It gives me a warning saying that converter may not respond to -free, and once I finish my program, it spits out a bun...

[self class] in Objective-C

I'm reading through Mark Dalrymple's Learn Objective-C on the Mac (only at the chapter on Protocols, so still relatively newbish) and trying to figure something out: Why would you ever reference a class by its own name? If I had a class called Foo, why would I ever want to write, say, [[Foo alloc] init] and not [[[self class] alloc...

Does any operating system implement buffering for malloc() ?

A lot of c/malloc()'s in a for/while/do can consume a lot of time so I am curious if any operating system buffers memory for fast mallocs. I have been pondering if I could speed up malloc's by writing a "greedy" wrapper for malloc. E.g. when I ask for 1MB of memory the initial allocator would allocate 10MB and on the 2nd, 3rd, 4th etc.....

[NPAPI] NPN_MemAlloc after NPN_MemFree screws the returning data to Google Chrome

Hi, I've finished my NPAPI plug-in and it works great in Google Chrome but there's a strange problem. The problem is that I've coded a method in the plug-in that returns a string to the browser. In order to do so, you have to allocate a memory in the browser and copy the resulting string to it. Something like: bool ScriptablePluginObje...