Skip to content

Commit

Permalink
corec: make the default heap private
Browse files Browse the repository at this point in the history
It's cleaner than an extern variable. The linker may optimize this.
  • Loading branch information
robUx4 committed Jan 4, 2025
1 parent da1e44b commit 830d183
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions corec/corec/array/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -577,5 +577,9 @@ static void* __HAlloc(const void* UNUSED_PARAM(p),size_t Size) { return malloc(S
static void __HFree(const void* UNUSED_PARAM(p),void* Ptr,size_t UNUSED_PARAM(Size)) { free(Ptr); }\
static void* __HReAlloc(const void* UNUSED_PARAM(p),void* Ptr,size_t UNUSED_PARAM(OldSize),size_t Size) { return realloc(Ptr,Size); }\
static void __HWrite(const void* UNUSED_PARAM(p),void* Ptr,const void* Src,size_t Pos,size_t Size) { memcpy((uint8_t*)Ptr+Pos,Src,Size); }\
static const cc_memheap MemHeap_Default_ = { __HAlloc,__HFree,__HReAlloc,__HWrite, &MemHeap_Default_, DATA_FLAG_MEMHEAP };
const cc_memheap *MemHeap_Default = &MemHeap_Default_;
static const cc_memheap MemHeap_Default = { __HAlloc,__HFree,__HReAlloc,__HWrite, &MemHeap_Default, DATA_FLAG_MEMHEAP };

const cc_memheap *MemHeap_GetDefault(void)
{
return &MemHeap_Default;
}
2 changes: 1 addition & 1 deletion corec/corec/memheap.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct cc_memheap
MEMHEAD_POINTER_HOLDER;
};

extern const cc_memheap *MemHeap_Default;
const cc_memheap *MemHeap_GetDefault(void);

static INLINE void *MemHeap_Alloc(const cc_memheap *p, size_t s)
{
Expand Down
2 changes: 1 addition & 1 deletion corec/corec/node/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -2610,7 +2610,7 @@ void NodeContext_Init(nodecontext* p,const nodemeta* Custom, const cc_memheap* H
ArrayInitEx(&p->NodeClass,Heap);
}
else
Heap = MemHeap_Default;
Heap = MemHeap_GetDefault();

if (!ConstHeap)
ConstHeap=Heap;
Expand Down

0 comments on commit 830d183

Please sign in to comment.