From 5b59852406e3d4a494186dddf9a5702062901668 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Wed, 11 Jul 2018 16:39:16 +0200 Subject: system.substr is not implemented with compilerProcs anymore --- lib/core/allocators.nim | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) (limited to 'lib/core/allocators.nim') diff --git a/lib/core/allocators.nim b/lib/core/allocators.nim index 62f5e9756..74a8d3753 100644 --- a/lib/core/allocators.nim +++ b/lib/core/allocators.nim @@ -8,28 +8,40 @@ # type + AllocatorFlag* {.pure.} = enum ## flags describing the properties of the allocator + ThreadLocal ## the allocator is thread local only. + ZerosMem ## the allocator always zeros the memory on an allocation Allocator* = ptr object {.inheritable.} alloc*: proc (a: Allocator; size: int; alignment: int = 8): pointer {.nimcall.} dealloc*: proc (a: Allocator; p: pointer; size: int) {.nimcall.} realloc*: proc (a: Allocator; p: pointer; oldSize, newSize: int): pointer {.nimcall.} + flags*: set[AllocatorFlag] var - currentAllocator {.threadvar.}: Allocator + localAllocator {.threadvar.}: Allocator + sharedAllocator: Allocator -proc getCurrentAllocator*(): Allocator = - result = currentAllocator +proc getLocalAllocator*(): Allocator = + result = localAllocator -proc setCurrentAllocator*(a: Allocator) = - currentAllocator = a +proc setLocalAllocator*(a: Allocator) = + localAllocator = a -proc alloc*(size: int; alignment: int = 8): pointer = - let a = getCurrentAllocator() - result = a.alloc(a, size, alignment) +proc getSharedAllocator*(): Allocator = + result = sharedAllocator -proc dealloc*(p: pointer; size: int) = - let a = getCurrentAllocator() - a.dealloc(a, p, size) +proc setSharedAllocator*(a: Allocator) = + sharedAllocator = a -proc realloc*(p: pointer; oldSize, newSize: int): pointer = - let a = getCurrentAllocator() - result = a.realloc(a, p, oldSize, newSize) +when false: + proc alloc*(size: int; alignment: int = 8): pointer = + let a = getCurrentAllocator() + result = a.alloc(a, size, alignment) + + proc dealloc*(p: pointer; size: int) = + let a = getCurrentAllocator() + a.dealloc(a, p, size) + + proc realloc*(p: pointer; oldSize, newSize: int): pointer = + let a = getCurrentAllocator() + result = a.realloc(a, p, oldSize, newSize) -- cgit 1.4.1-2-gfad0 From 4ec91a30c4ab4bdb45f9805168f124205235d19c Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Fri, 27 Jul 2018 18:19:18 +0200 Subject: allocators: add deallocAll proc pointer --- lib/core/allocators.nim | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/core/allocators.nim') diff --git a/lib/core/allocators.nim b/lib/core/allocators.nim index 74a8d3753..f652f0d85 100644 --- a/lib/core/allocators.nim +++ b/lib/core/allocators.nim @@ -15,6 +15,7 @@ type alloc*: proc (a: Allocator; size: int; alignment: int = 8): pointer {.nimcall.} dealloc*: proc (a: Allocator; p: pointer; size: int) {.nimcall.} realloc*: proc (a: Allocator; p: pointer; oldSize, newSize: int): pointer {.nimcall.} + deallocAll*: proc (a: Allocator) {.nimcall.} flags*: set[AllocatorFlag] var -- cgit 1.4.1-2-gfad0