-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable memtracing for stb and zstd (#227)
- **ADDED** Longtail_SetReAllocAndFree - **ADDED** Longtail_ReAlloc - **ADDED** Longtail_MemTracer_ReAlloc - **ADDED** memtracer now tracks allocations in stb_ds - **ADDED** memtracer now tracks allocations in zstd
- Loading branch information
1 parent
0bcc0a0
commit 32cfa38
Showing
12 changed files
with
159 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
set CXXFLAGS=%CXXFLAGS% /wd4244 /wd4316 /wd4996 /DLONGTAIL_LOG_LEVEL=5 /D__SSE2__ | ||
set CXXFLAGS_DEBUG=%CXXFLAGS_DEBUG% /DBIKESHED_ASSERTS /DLONGTAIL_ASSERTS /D_DEBUG /DLONGTAIL_LOG_LEVEL=3 /D__SSE2__ /DLONGTAIL_EXPORT_SYMBOLS /DZSTDLIB_VISIBILITY="" /DLZ4LIB_VISIBILITY="" | ||
set CXXFLAGS_DEBUG=%CXXFLAGS_DEBUG% /DBIKESHED_ASSERTS /DLONGTAIL_ASSERTS /D_DEBUG /DLONGTAIL_LOG_LEVEL=3 /D__SSE2__ /DLONGTAIL_EXPORT_SYMBOLS /DZSTDLIB_VISIBILITY="" /DLZ4LIB_VISIBILITY="" /DSTBDS_REALLOC=Longtail_STBRealloc /DSTBDS_FREE=Longtail_STBFree |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/bin/bash | ||
|
||
export CXXFLAGS="$CXXFLAGS -pthread -U_WIN32 -DLONGTAIL_LOG_LEVEL=5" | ||
export CXXFLAGS_DEBUG="$CXXFLAGS_DEBUG -DBIKESHED_ASSERTS -DLONGTAIL_LOG_LEVEL=3 -DLONGTAIL_ASSERTS" | ||
export CXXFLAGS_DEBUG="$CXXFLAGS_DEBUG -DBIKESHED_ASSERTS -DLONGTAIL_LOG_LEVEL=3 -DLONGTAIL_ASSERTS -DSTBDS_REALLOC=Longtail_STBRealloc -DSTBDS_FREE=Longtail_STBFree" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
|
||
#include <errno.h> | ||
#include <inttypes.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#if !defined(alloca) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,22 @@ | ||
#define STB_DS_IMPLEMENTATION | ||
|
||
//#define CUSTOM_STB_ALLOC | ||
|
||
#ifdef STBDS_REALLOC | ||
|
||
#define CUSTOM_STB_ALLOC 1 | ||
extern void* Longtail_STBRealloc(void* old_ptr, size_t size); | ||
extern void Longtail_STBFree(void* ptr); | ||
|
||
|
||
// TODO These needs to be defined at a global level! | ||
//#define STBDS_REALLOC(context,ptr,size) Longtail_STBRealloc((ptr), (size)) | ||
//#define STBDS_FREE(context,ptr) Longtail_STBFree((ptr)) | ||
|
||
#endif // STBDS_REALLOC | ||
|
||
#include "../longtail.h" | ||
#include "stb_ds.h" | ||
|
||
#if CUSTOM_STB_ALLOC | ||
|
||
#include <stddef.h> | ||
#include <stdint.h> | ||
|
||
extern void* Longtail_Alloc(const char* context, size_t s); | ||
extern void Longtail_Free(void* p); | ||
|
||
struct Longtail_STBAllocHeader | ||
{ | ||
uint64_t Size; | ||
uint64_t _; | ||
}; | ||
|
||
inline void* Longtail_STBRealloc(void* old_ptr, size_t size) | ||
void* Longtail_STBRealloc(void* context, void* old_ptr, size_t size) | ||
{ | ||
if (size == 0) | ||
{ | ||
return 0; | ||
} | ||
struct Longtail_STBAllocHeader* header = (struct Longtail_STBAllocHeader*)Longtail_Alloc("stb", sizeof(struct Longtail_STBAllocHeader) + size); | ||
header->Size = size; | ||
header->_ = 0; | ||
void* new_ptr = &header[1]; | ||
if (old_ptr != 0) | ||
{ | ||
struct Longtail_STBAllocHeader* old_header = &((struct Longtail_STBAllocHeader*)old_ptr)[-1]; | ||
size_t old_size = old_header->Size; | ||
memcpy(new_ptr, old_ptr, old_size); | ||
Longtail_Free((void*)old_header); | ||
} | ||
return new_ptr; | ||
return Longtail_ReAlloc("stb", old_ptr, size); | ||
} | ||
|
||
inline void Longtail_STBFree(void* ptr) | ||
void Longtail_STBFree(void* context, void* ptr) | ||
{ | ||
if (!ptr) | ||
{ | ||
return; | ||
} | ||
struct Longtail_STBAllocHeader* header = &((struct Longtail_STBAllocHeader*)ptr)[-1]; | ||
Longtail_Free((void*)header); | ||
Longtail_Free(ptr); | ||
} | ||
|
||
#endif // CUSTOM_STB_ALLOC | ||
#else | ||
|
||
#include "stb_ds.h" | ||
|
||
#endif // STBDS_REALLOC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.