Blender memory guarded allocation (mallocn.c)

Compiling, libraries, modules, coding guidelines and porting

Moderators: jesterKing, stiv

Post Reply
mjordan
Posts: 0
Joined: Tue Nov 23, 2004 3:33 pm

Blender memory guarded allocation (mallocn.c)

Post by mjordan »

Hi!
I'm trying to figure out how the guarded memory allocation works in blender. I'm reading the code inside mallocn.c and I'm struggling against the meaning of two defined macros.

The first one, MAKE_ID, for big endian machines, is defined as:

Code: Select all

MAKE_ID(a, b, c, d) ( (int)(a) << 24 | (int)(b) << 16 | (c) << 8 | (d))
while for little endian machines it's defined as:

Code: Select all

MAKE_ID(a, b, c, d) ( (int)(d) << 24 | (int)(c) << 16 | (b) << 8 | (a))
I can't undestand the "semantic" meaning. Is this a sort of hashing? They give the same results for little and big endian machines? Also, why only the first two parameters are casted to int? What is the logic behind this?

The second defined macro:

Code: Select all

MEMNEXT(x) ((MemHead *)(((char *)x) - ((char *)&(((MemHead *)0)->next))))
My C knowledge can't permit me seeing what it means... Please explain me ...

Thank you in advance...
Regards,
Renato Perini
-
You can't live with women, you can't live without women.
Fuzzy logic example.

Post Reply