SDL icon indicating copy to clipboard operation
SDL copied to clipboard

alloc api having new attributes for micro optimisations.

Open devnexen opened this issue 2 years ago • 2 comments

  • SDL_MALLOC when the pointer returned is not aliased.
  • SDL_ALLOC_SIZE* to gives hint about the size.

devnexen avatar Sep 04 '22 14:09 devnexen

GCC 11 added attribute malloc (deallocator, ptr-index) which detects mismatched allocation and deallocation functions (like the one found in 4ada14a) . It could be useful for objects that need a specific deallocator like SDL_CreateRGBSurface()/SDL_FreeSurface().

example: __attribute__((malloc, malloc (fclose, 1))) FILE* fopen(const char*, const char*);

https://gcc.gnu.org/onlinedocs/gcc-11.3.0/gcc/Common-Function-Attributes.html#Common-Function-Attributes

meyraud705 avatar Sep 05 '22 15:09 meyraud705

GCC 11 added attribute malloc (deallocator, ptr-index) which detects mismatched allocation and deallocation functions (like the one found in 4ada14a) . It could be useful for objects that need a specific deallocator like SDL_CreateRGBSurface()/SDL_FreeSurface().

example: __attribute__((malloc, malloc (fclose, 1))) FILE* fopen(const char*, const char*);

https://gcc.gnu.org/onlinedocs/gcc-11.3.0/gcc/Common-Function-Attributes.html#Common-Function-Attributes

I know but clang does not :-|

devnexen avatar Sep 05 '22 15:09 devnexen

(Nominating this for SDL3.)

icculus avatar Sep 28 '22 14:09 icculus

If the deallocation attribute make sense later, and doesn't need us to make drastic changes to support it, let's talk about that in a separate issue or PR.

icculus avatar Nov 23 '22 18:11 icculus