/*Copyright (c) DataStax, Inc.Licensed under the Apache License, Version 2.0 (the "License");you may not use this file except in compliance with the License.You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.*/#include "memory.hpp"#include <assert.h>#include <new>#include <string.h>#include <uv.h>using namespace datastax::internal;extern "C" {void cass_alloc_set_functions(CassMallocFunction malloc_func, CassReallocFunction realloc_func,CassFreeFunction free_func) {Memory::set_functions(malloc_func, realloc_func, free_func);}} // extern "C"#ifdef DEBUG_CUSTOM_ALLOCATORvoid* operator new(size_t size) throw(std::bad_alloc) {assert(false && "Attempted to use global operator new");return cass::Memory::malloc(size);}void* operator new[](size_t size) throw(std::bad_alloc) {assert(false && "Attempted to use global operator new[]");return cass::Memory::malloc(size);}void operator delete(void* ptr) throw() {assert(false && "Attempted to use global operator delete");cass::Memory::free(ptr);}void operator delete[](void* ptr) throw() {assert(false && "Attempted to use global operator delete[]");cass::Memory::free(ptr);}#endifCassMallocFunction Memory::malloc_func_ = NULL;CassReallocFunction Memory::realloc_func_ = NULL;CassFreeFunction Memory::free_func_ = NULL;#if UV_VERSION_MAJOR >= 1 && UV_VERSION_MINOR >= 6static void* calloc_(size_t count, size_t size) {void* ptr = Memory::malloc(count * size);if (ptr != NULL) {memset(ptr, 0, count * size);}return ptr;}#endifvoid Memory::set_functions(CassMallocFunction malloc_func, CassReallocFunction realloc_func,CassFreeFunction free_func) {if (malloc_func == NULL || realloc_func == NULL || free_func == NULL) {Memory::malloc_func_ = NULL;Memory::realloc_func_ = NULL;Memory::free_func_ = NULL;} else {Memory::malloc_func_ = malloc_func;Memory::realloc_func_ = realloc_func;Memory::free_func_ = free_func;}#if UV_VERSION_MAJOR >= 1 && UV_VERSION_MINOR >= 6uv_replace_allocator(Memory::malloc_func_, Memory::realloc_func_, calloc_, Memory::free_func_);#endif}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。