PDA

View Full Version : Memory management questions




MorphingDragon
Oct 8, 2010, 07:45 AM
The University has random contests once in a while for... well whatever they feel like giving away. The limitation is that it has to be a high-level OOP programming language and it can't use premade libraries to achieve the given task.

Anyway, this time is to make a terminal program which will decompress a 5GB Zip File. Whoever's Application uses the least memory for the amount of time it takes to open the zip file wins.

I have some memory management questions.

Does an Autorelease pool adhere to data encapsulation?

How costly is an auto release pool compared to just using retain/release manually.

How do you free up memory from C primitives? (I know like... no C) Both on the stack and using pointers.

Can C/Objective-C stream raw data to a file on the disk instead of memory? How would I do that?



(marc)
Oct 8, 2010, 01:05 PM
int i = 0 // C manages the memory for you. The memory's released when the variable is out of scope
int *j = malloc(sizeof(int)) // You have to release the memory with free()

By the way, I think it's somewhat strange that you have to use a high-level OO language. If you want to keep memory usage down, C is the language to go with. Also, ZIP files can be compressed using various techniques, so since you aren't allowed to use existing libraries, you'll have to write a whole bunch of code from scratch.

MorphingDragon
Oct 8, 2010, 05:41 PM
int i = 0 // C manages the memory for you. The memory's released when the variable is out of scope
int *j = malloc(sizeof(int)) // You have to release the memory with free()

Thanks

[CODE]By the way, I think it's somewhat strange that you have to use a high-level OO language. If you want to keep memory usage down, C is the language to go with.

I think thats the point. Give them a language that naturally has more bloat than C and make it as efficient as possible.


Also, ZIP files can be compressed using various techniques, so since you aren't allowed to use existing libraries, you'll have to write a whole bunch of code from scratch.

I think thats also the point.

Sydde
Oct 8, 2010, 06:37 PM
Also, ZIP files can be compressed using various techniques, so since you aren't allowed to use existing libraries, you'll have to write a whole bunch of code from scratch.

But why from scratch? There is plenty of open source that you could copy from and just make some small adjustments to make it take advantage of the OOP environment. It is not for production, so licensing will not be a concern.

But I am not getting "least amount of memory for the amount of time". If your code uses twice the memory of another one that takes three times as long, yours would come out ahead, right?

MorphingDragon
Oct 8, 2010, 07:07 PM
But why from scratch?

Its a competition. Competitions have arbitrary rules.

Thats reason enough I suppose. Though it might be to weed out the incompetent programmers?

But I am not getting "least amount of memory for the amount of time". If your code uses twice the memory of another one that takes three times as long, yours would come out ahead, right?

Yes, this particular problem is about efficiency, not pure speed. (I'm not sure how they would get the score though)

We get the rest of the information later. This is just what I know from the posters they've left around the CS department.

(marc)
Oct 9, 2010, 09:52 AM
Thanks



I think thats the point. Give them a language that naturally has more bloat than C and make it as efficient as possible.



I think thats also the point.

Will the solutions be put online? I'd love to take a look at the code when it's finished!

EDIT: I got a bit intrigued on the subject, so I did a bit of "research" about how the JVM works. I found this (http://www.herongyang.com/JVM/memory_2.html). At the very end, it says "you can see that the garbage collector only starts to work when the free memory is getting close the specified maximum, 64MB". I don't know if that's really true and I also don't know how the Objective-C runtime handles autorelease pools / garbage collection. It's just a thing to keep in mind, especially for the CS department during evaluation. Do you know how they deal with these problems?

jared_kipe
Oct 9, 2010, 10:17 AM
I personally believe it would be possible to write an objective-C program without relying on Autorelease, though you could setup a pool just to catch anything Apple shoves into the autorelease pool without you knowing.

You would have to change the normal objective C paradigm that methods that return an object autorelease it before it returns though. But if you use alloc/init instead of convenience methods you should be fine.

MorphingDragon
Oct 9, 2010, 05:09 PM
Will the solutions be put online? I'd love to take a look at the code when it's finished!

No they don't, unfortunately.

Last year apparently the final competition was to make a 3D game enigne! I'd love to see some of that code. :/

mac2x
Oct 9, 2010, 05:31 PM
No they don't, unfortunately.

Last year apparently the final competition was to make a 3D game enigne! I'd love to see some of that code. :/


Wow! That would definitely separate the men from the boys, so to speak. :D

MorphingDragon
Oct 9, 2010, 11:09 PM
Wow! That would definitely separate the men from the boys, so to speak. :D

Surprisingly there is a massive lack of information on how to make a game engine. The closest we have in terms of a book is:

http://www.amazon.com/Game-Engine-Architecture-Jason-Gregory/dp/1568814135/ref=sr_1_1?ie=UTF8&qid=1286683728&sr=8-1

and thats considered quite lacking. Like you can get books on the separate topics of game engine design but there's not really any books that link it all together