Category : malloc

I am trying to write some tests in Catch2 (a C++ library) for a simple C library example and I am a little confused about how to initialize a C struct. My C header looks like this: struct node; And my C implementation cannot be simpler: struct node { int num; struct node* next; } ..

Read more

I implemented a custom operator new to track allocation behaviour. It allocates 8 bytes more than requested to prepend the allocated size as std::size_t. void *operator new(std::size_t count) { auto *pBase = reinterpret_cast<std::size_t*>(std::malloc(count + sizeof(std::size_t))); pBase[0] = count; auto *pUserMem = reinterpret_cast<std::byte*>(pBase) + sizeof(std::size_t); return reinterpret_cast<void*>(pUserMem); } Additionally I reimplemented operator delete to (in a ..

Read more