Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C GENERIC PROGRAMMING?

Name: Anonymous 2011-02-13 12:02

http://dis.4chan.org/read/prog/1297507372/56

i was reworking my memory manager a little bit (trying to get rid of memset initialization by keeping a mem_biggest_used_index variable) and i suddenly noticed that there's another problem i didn't consider: i'll have to duplicate all this code for every type of object pool i want. i'll need at least a pool for items and another one for NPCs. WHAT DO NOW?!

i found some code online and threw up in my mouth, is this how it's done in C?

http://www.flipcode.com/archives/Faking_Templates_In_C.shtml

Name: Anonymous 2011-02-13 12:07

The pleasure of C preprocessor macros

Name: Anonymous 2011-02-13 12:12

>>1
Yes. Look for my implementation of a type-safe linked list using macros, it's somewhere here on /prog/!

Really though, what did you expect? And macros are cool.

Name: Anonymous 2011-02-13 12:25

Yes, if you do need to instantiate something based on type, this is a way to do it. See https://github.com/attractivechaos/klib for some reputable examples.

Though honestly, writing your own memory manager? Premature optimisation, anyone? If you really know that you'll need efficient memory allocation, try using something like http://library.gnome.org/devel/glib/stable/glib-Memory-Slices.html, or any of a dozen other custom allocators.

Name: OP 2011-02-13 12:45

>>4
yah, i don't really know what i'm doing... just trying to wrestle myself through this. i checked out the links, mem slices look really interesting, might be just what i need. still, for the sake of learning something, i think i'll try to carry on with this code for a day or two longer.

anyways, now is time for me to get hgih so i'll ttyl when i reviewed the links and my options... for some reason i believe turning mem_pool into a void* + a lot of casts (and a macro or two) might work...

i'll report back later

Name: Anonymous 2011-02-13 12:48

>>5
now is time for me to get hgih so i'll ttyl
Bloody druggie.

Name: Anonymous 2011-02-13 12:48

what is that faggot shit. kill yourself OP. your writing a gay rpg ffs

Name: Anonymous 2011-02-13 13:37

>>7
Gay rpgs are quite cool. What's your problem with that?

Name: Anonymous 2011-02-13 13:43

>>8
My problem with gay RPG is that there aren't nearly enough of them.
I can't be a cute gay barely-legal shota in a relationship with a manly protective mentor-figure guy like this!!

Name: Anonymous 2011-02-13 13:59

I suggest you work on the high level stuff of your game before the low level stuff like this. You need to nail down the high level stuff first to discover what kind of interface you actually need to the low level stuff. If you don't, it's too easy to run in circles trying to make overly general code. The fact that you are writing a "memory manager" smells strongly of this problem.

Name: Anonymous 2011-02-13 14:27

And this gentlemen, is why                       C++             is better than          C             .

Name: Anonymous 2011-02-13 14:58

>>11
nice try

Name: Anonymous 2011-02-13 15:23

>>11
And then you discover D.

Name: Anonymous 2011-02-13 15:38

>>13
'C'++

Name: Anonymous 2011-02-13 17:12

>>10
this smells like good advice. i will concentrate on my game mechanics for a bit and come back when i have a better idea of what my memory requirements are.

something tell me though, i wont end up malloc-ing a fresh part of memory for every npc/game item, but it can't hurt to do it until i think of something better.

Name: Anonymous 2011-02-13 17:42

Please consider bumping your old thread instead of making new ones.

Name: Anonymous 2011-02-13 17:55

>>14
i chagrined

Name: Anonymous 2011-02-13 21:03

>>14
many anii were hurt

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List