@@ -71,7 +71,7 @@ static void OnMessage(Local<Message> message, Local<Value> error) {
7171 }
7272}
7373
74- void * ArrayBufferAllocator ::Allocate (size_t size) {
74+ void * NodeArrayBufferAllocator ::Allocate (size_t size) {
7575 if (zero_fill_field_ || per_process::cli_options->zero_fill_all_buffers )
7676 return UncheckedCalloc (size);
7777 else
@@ -84,29 +84,29 @@ DebuggingArrayBufferAllocator::~DebuggingArrayBufferAllocator() {
8484
8585void * DebuggingArrayBufferAllocator::Allocate (size_t size) {
8686 Mutex::ScopedLock lock (mutex_);
87- void * data = ArrayBufferAllocator ::Allocate (size);
87+ void * data = NodeArrayBufferAllocator ::Allocate (size);
8888 RegisterPointerInternal (data, size);
8989 return data;
9090}
9191
9292void * DebuggingArrayBufferAllocator::AllocateUninitialized (size_t size) {
9393 Mutex::ScopedLock lock (mutex_);
94- void * data = ArrayBufferAllocator ::AllocateUninitialized (size);
94+ void * data = NodeArrayBufferAllocator ::AllocateUninitialized (size);
9595 RegisterPointerInternal (data, size);
9696 return data;
9797}
9898
9999void DebuggingArrayBufferAllocator::Free (void * data, size_t size) {
100100 Mutex::ScopedLock lock (mutex_);
101101 UnregisterPointerInternal (data, size);
102- ArrayBufferAllocator ::Free (data, size);
102+ NodeArrayBufferAllocator ::Free (data, size);
103103}
104104
105105void * DebuggingArrayBufferAllocator::Reallocate (void * data,
106106 size_t old_size,
107107 size_t size) {
108108 Mutex::ScopedLock lock (mutex_);
109- void * ret = ArrayBufferAllocator ::Reallocate (data, old_size, size);
109+ void * ret = NodeArrayBufferAllocator ::Reallocate (data, old_size, size);
110110 if (ret == nullptr ) {
111111 if (size == 0 ) // i.e. equivalent to free().
112112 UnregisterPointerInternal (data, old_size);
@@ -149,11 +149,15 @@ void DebuggingArrayBufferAllocator::RegisterPointerInternal(void* data,
149149 allocations_[data] = size;
150150}
151151
152- ArrayBufferAllocator* CreateArrayBufferAllocator ( ) {
153- if (per_process::cli_options->debug_arraybuffer_allocations )
154- return new DebuggingArrayBufferAllocator ();
152+ std::unique_ptr< ArrayBufferAllocator> ArrayBufferAllocator::Create ( bool debug ) {
153+ if (debug || per_process::cli_options->debug_arraybuffer_allocations )
154+ return std::make_unique< DebuggingArrayBufferAllocator> ();
155155 else
156- return new ArrayBufferAllocator ();
156+ return std::make_unique<NodeArrayBufferAllocator>();
157+ }
158+
159+ ArrayBufferAllocator* CreateArrayBufferAllocator () {
160+ return ArrayBufferAllocator::Create ().release ();
157161}
158162
159163void FreeArrayBufferAllocator (ArrayBufferAllocator* allocator) {
0 commit comments