+ 1

How signed or unsigned integers are used to keep track of heap-allocated objects in C?

Many OpenGL functions; for instance, "GLuint glCreateShader()" keep track of created objects (in this case, a "Shader" object) without returning a pointer. Because the maximum size of an unsigned can be 4 bytes, so it wouldn't make sense to cast it to a pointer type (since a pointer has a size of 8 bytes) to use it as a reference to the created "Shader" object. I hope it is clear enough. Hope someone with proper knowledge would give an answer or give a reference of some sort. Thanks

22nd Dec 2020, 3:02 AM
Lucas
9 Réponses
+ 1
Did you understand the question? Sonic
22nd Dec 2020, 10:14 AM
Lucas
+ 1
Lucas perhaps not 100% as I don't use OpenGL. Would you mind elaborating?
22nd Dec 2020, 8:21 PM
Sonic
Sonic - avatar
+ 1
Sonic It's been explained already. It's not about opengl, but how opengl implements such functions Anyway, it's better not to answer if someone may lack knowledge about something. Thanks
22nd Dec 2020, 8:57 PM
Lucas
+ 1
Perhaps you can post the question in a Khronos forum?
22nd Dec 2020, 9:39 PM
Sonic
Sonic - avatar
0
Pointers are 8 bytes long because they store addresses. What is contained at or starts at those addresses in the heap can be any length.
22nd Dec 2020, 4:29 AM
Sonic
Sonic - avatar
0
Martin Taylor i know it's not a pointer. I wanted to know, how could i write such kind of function. Any idea how one can implement such function i.e. return a handle instead of a pointer and do all the things (access, update. ..)?
23rd Dec 2020, 12:40 AM
Lucas
0
Martin Taylor well, I'm not writing any game. It's a bit of pity to get judged about knowledge/experience based on some silly XP convention. bringing "OpenGL" to ask about a C related question was to give an example. The underlying question was "how a handle can be used to manipulate an object in heap-allocated memory?". Even WIN32 API also returns handles, but that handle is a simple "void*" with a size of 8 bytes, so it could technically be cast to the desired pointer. I'm not solving any homework, and "not showing any attempt" is not appropriate for this particular question I think. I actually searched a bit online before asking this question but failed to get any valid implementation of OpenGL. Could you point me one? I like the idea of using a "map", but you mentioned there are other ways. Could you just mention those? I just need the names/terms then I should be able to implement them myself. Thanks
23rd Dec 2020, 3:30 PM
Lucas