Handmade Hero » Forums » Code » b32x, memory_index, umm, smm
mrmixer
Simon Anciaux
493 posts
#8140 b32x, memory_index, umm, smm
2 years, 3 months ago

In one of the last episodes, Casey tried to use the b32x type which is not defined in the handmade hero code base. What would be the purpose (or conceptual meaning) of that type, and would it be the same typedef as b32 ?

On the same topic what are the different use case for memory_index (size_t) and umm (uintptr_t) as they are defined exactly the same way ?

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#ifdef  _WIN64
typedef unsigned __int64    size_t;
#else
typedef _W64 unsigned int   size_t;
#endif

#ifdef  _WIN64
typedef unsigned __int64    uintptr_t;
#else
typedef _W64 unsigned int   uintptr_t;
#endif
graeme
34 posts
#8144 b32x, memory_index, umm, smm
2 years, 3 months ago

Can't speak to b32x, but size_t and uintptr_t can be defined differently on certain platforms

From cppreference
uintptr_t - unsigned integer type capable of holding a pointer

size_t can store the maximum size of a theoretically possible object of any type (including array).

As I understand it on systems with segmented memory, size_t used as an index would hold only an offset within a segment, but uintptr_t would hold both a segment and an offset.
cmuratori
Casey Muratori
817 posts / 1 project

Casey Muratori is a programmer at Molly Rocket on the game 1935 and is the host of the educational programming series Handmade Hero.

#8145 b32x, memory_index, umm, smm
2 years, 3 months ago

b32x is just "boolean value in whatever size is comfortable for the compiler but not less than 32 bits." It's what you use when you're working with s32/u32 and want to store a boolean but don't care if it expands to 64 bits (or more) on some theoretical architecture where that was more efficient.

- Casey
mrmixer
Simon Anciaux
493 posts
#8149 b32x, memory_index, umm, smm
2 years, 3 months ago

I would like to rephrase my question: Given that memory_index and umm are implemented the same, are there cases where you specifically use memory_index or umm to give additional meaning to some code ?

@cmuratori: So is it
1
typedef int_least32_t b32x
cmuratori
Casey Muratori
817 posts / 1 project

Casey Muratori is a programmer at Molly Rocket on the game 1935 and is the host of the educational programming series Handmade Hero.

#8159 b32x, memory_index, umm, smm
2 years, 3 months ago

We don't really need both, no - we could replace memory_index (and probably should) now that we have umm/smm.

- Casey
bimbinel
14 posts
#10461 b32x, memory_index, umm, smm
1 year, 10 months ago

Btw what does mm stand for?
mmozeiko
Mārtiņš Možeiko
1833 posts / 1 project
#10462 b32x, memory_index, umm, smm
1 year, 10 months ago

memory mapped?
ratchetfreak
419 posts
#10463 b32x, memory_index, umm, smm
1 year, 10 months ago

bimbinel
Btw what does mm stand for?


It's probably an adaptation from the meaningless MMX initialism
cmuratori
Casey Muratori
817 posts / 1 project

Casey Muratori is a programmer at Molly Rocket on the game 1935 and is the host of the educational programming series Handmade Hero.

#10464 b32x, memory_index, umm, smm
1 year, 10 months ago

It's just a shorthand for "the size that a pointer is". There's no rhyme or reason for it. The "m" stands for "memory" but there's no reason it has to be two of them, I think I just liked the way that looked better than "um" and "sm".

- Casey