本文整理汇总了C++中TRI_Allocate函数的典型用法代码示例。如果您正苦于以下问题:C++ TRI_Allocate函数的具体用法?C++ TRI_Allocate怎么用?C++ TRI_Allocate使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TRI_Allocate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TRI_InsertVector
void TRI_InsertVector (TRI_vector_t* vector, void const* element, size_t position) {
char* newBuffer;
// ...........................................................................
// Check and see if we need to extend the vector
// ...........................................................................
if (vector->_length >= vector->_capacity || position >= vector->_length) {
size_t newSize = (size_t) (1 + (GROW_FACTOR * vector->_capacity));
if (position >= newSize) {
newSize = position + 1;
}
newBuffer = (char*) TRI_Allocate(vector->_memoryZone, newSize * vector->_elementSize, false);
if (newBuffer == NULL) {
TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY);
return;
}
vector->_capacity = newSize;
if (vector->_buffer != NULL) {
memcpy(newBuffer, vector->_buffer, vector->_length * vector->_elementSize);
TRI_Free(vector->_memoryZone, vector->_buffer);
}
vector->_buffer = newBuffer;
}
if (position < vector->_length) {
memmove(vector->_buffer + (vector->_elementSize * (position + 1)),
vector->_buffer + (vector->_elementSize * position),
vector->_elementSize * (vector->_length - position)
);
vector->_length += 1;
}
else {
vector->_length = position + 1;
}
memcpy(vector->_buffer + (vector->_elementSize * position), element, vector->_elementSize);
}
示例2: TRI_CreateSimpleHeaders
TRI_headers_t* TRI_CreateSimpleHeaders (size_t headerSize) {
simple_headers_t* headers = TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(simple_headers_t), false);
if (headers == NULL) {
TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY);
return NULL;
}
headers->base.request = RequestSimpleHeaders;
headers->base.verify = VerifySimpleHeaders;
headers->base.release = ReleaseSimpleHeaders;
headers->_freelist = NULL;
headers->_headerSize = headerSize;
TRI_InitVectorPointer(&headers->_blocks, TRI_UNKNOWN_MEM_ZONE);
return &headers->base;
}
示例3: TRI_CopyToBlob
int TRI_CopyToBlob (TRI_memory_zone_t* zone, TRI_blob_t* dst, TRI_blob_t const* src) {
dst->length = src->length;
if (src->length == 0 || src->data == nullptr) {
dst->length = 0;
dst->data = nullptr;
}
else {
dst->data = static_cast<char*>(TRI_Allocate(zone, dst->length, false));
if (dst->data == nullptr) {
return TRI_ERROR_OUT_OF_MEMORY;
}
memcpy(dst->data, src->data, src->length);
}
return TRI_ERROR_NO_ERROR;
}
示例4: TRI_CreateGeo1Index
TRI_index_t* TRI_CreateGeo1Index (TRI_document_collection_t* document,
TRI_idx_iid_t iid,
char const* locationName,
TRI_shape_pid_t location,
bool geoJson,
bool unique,
bool ignoreNull) {
char* ln;
TRI_geo_index_t* geo = static_cast<TRI_geo_index_t*>(TRI_Allocate(TRI_CORE_MEM_ZONE, sizeof(TRI_geo_index_t), false));
TRI_index_t* idx = &geo->base;
TRI_InitVectorString(&idx->_fields, TRI_CORE_MEM_ZONE);
TRI_InitIndex(idx, iid, TRI_IDX_TYPE_GEO1_INDEX, document, unique, false);
idx->_ignoreNull = ignoreNull;
idx->memory = MemoryGeoIndex;
idx->json = JsonGeo1Index;
idx->insert = InsertGeoIndex;
idx->remove = RemoveGeoIndex;
ln = TRI_DuplicateStringZ(TRI_CORE_MEM_ZONE, locationName);
TRI_PushBackVectorString(&idx->_fields, ln);
geo->_geoIndex = GeoIndex_new();
// oops, out of memory?
if (geo->_geoIndex == NULL) {
TRI_DestroyVectorString(&idx->_fields);
TRI_Free(TRI_CORE_MEM_ZONE, geo);
return NULL;
}
geo->_variant = geoJson ? INDEX_GEO_COMBINED_LAT_LON : INDEX_GEO_COMBINED_LON_LAT;
geo->_location = location;
geo->_latitude = 0;
geo->_longitude = 0;
geo->_geoJson = geoJson;
return idx;
}
示例5: FillIndexSearchValueByHashIndexElement
static int FillIndexSearchValueByHashIndexElement (TRI_hash_index_t* hashIndex,
TRI_index_search_value_t* key,
T* element) {
key->_values = static_cast<TRI_shaped_json_t*>(TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, KeyEntrySize(hashIndex), false));
if (key->_values == nullptr) {
return TRI_ERROR_OUT_OF_MEMORY;
}
char const* ptr = element->_document->getShapedJsonPtr(); // ONLY IN INDEX
size_t const n = NumPaths(hashIndex);
for (size_t i = 0; i < n; ++i) {
key->_values[i]._sid = element->_subObjects[i]._sid;
key->_values[i]._data.length = element->_subObjects[i]._length;
key->_values[i]._data.data = const_cast<char*>(ptr + element->_subObjects[i]._offset);
}
return TRI_ERROR_NO_ERROR;
}
示例6: TRI_CreateBarrierElementZ
TRI_barrier_t* TRI_CreateBarrierElementZ (TRI_barrier_list_t* container,
size_t line,
char const* filename) {
TRI_barrier_blocker_t* element;
element = TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_barrier_blocker_t), false);
if (element == NULL) {
return NULL;
}
element->base._type = TRI_BARRIER_ELEMENT;
element->_line = line;
element->_filename = filename;
LinkBarrierElement(&element->base, container);
return &element->base;
}
示例7: TRI_CopyToBlob
int TRI_CopyToBlob (TRI_memory_zone_t* zone, TRI_blob_t* dst, TRI_blob_t const* src) {
dst->length = src->length;
if (src->length == 0 || src->data == NULL) {
dst->length = 0;
dst->data = NULL;
}
else {
dst->length = src->length;
dst->data = TRI_Allocate(zone, dst->length, false);
if (dst->data == NULL) {
return TRI_ERROR_OUT_OF_MEMORY;
}
memcpy(dst->data, src->data, src->length);
}
return TRI_ERROR_NO_ERROR;
}
示例8: RequestSimpleHeaders
static TRI_doc_mptr_t* RequestSimpleHeaders (TRI_headers_t* h) {
simple_headers_t* headers = (simple_headers_t*) h;
char const* header;
union { TRI_doc_mptr_t const* c; TRI_doc_mptr_t* h; } c;
if (headers->_freelist == NULL) {
char* begin;
char* ptr;
size_t blockSize;
blockSize = GetBlockSize(headers->_blocks._length);
begin = TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, blockSize * headers->_headerSize, false);
// out of memory
if (begin == NULL) {
TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY);
return NULL;
}
ptr = begin + headers->_headerSize * (blockSize - 1);
header = NULL;
for (; begin <= ptr; ptr -= headers->_headerSize) {
ClearSimpleHeaders((TRI_doc_mptr_t*) ptr, headers->_headerSize);
((TRI_doc_mptr_t*) ptr)->_data = header;
header = ptr;
}
headers->_freelist = (TRI_doc_mptr_t*) header;
TRI_PushBackVectorPointer(&headers->_blocks, begin);
}
c.c = headers->_freelist;
headers->_freelist = c.c->_data;
c.h->_data = NULL;
return c.h;
}
示例9: TRI_CreateStringCopyJson
TRI_json_t* TRI_CreateStringCopyJson (TRI_memory_zone_t* zone, char const* value, size_t length) {
if (value == nullptr) {
// initial string should be valid...
return nullptr;
}
TRI_json_t* result = static_cast<TRI_json_t*>(TRI_Allocate(zone, sizeof(TRI_json_t), false));
if (result != nullptr) {
char* copy = TRI_DuplicateString2Z(zone, value, length);
if (copy == nullptr) {
TRI_Free(zone, result);
return nullptr;
}
InitString(result, copy, length);
}
return result;
}
示例10: TRI_CreateCollectionHintAql
TRI_aql_collection_hint_t* TRI_CreateCollectionHintAql (void) {
TRI_aql_collection_hint_t* hint;
hint = (TRI_aql_collection_hint_t*) TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_aql_collection_hint_t), false);
if (hint == NULL) {
return NULL;
}
hint->_ranges = NULL;
hint->_index = NULL;
hint->_collection = NULL;
hint->_variableName = NULL;
// init limit
hint->_limit._offset = 0;
hint->_limit._limit = INT64_MAX;
hint->_limit._status = TRI_AQL_LIMIT_UNDEFINED;
return hint;
}
示例11: TRI_RegisterMimetype
bool TRI_RegisterMimetype (const char* extension,
const char* mimetype,
bool appendCharset) {
mimetype_t* entry;
void* found;
entry = TRI_Allocate(TRI_CORE_MEM_ZONE, sizeof(mimetype_t), false);
entry->_extension = TRI_DuplicateString(extension);
entry->_appendCharset = appendCharset;
if (appendCharset) {
entry->_mimetype = TRI_Concatenate2String(mimetype, "; charset=utf-8");
}
else {
entry->_mimetype = TRI_DuplicateString(mimetype);
}
found = TRI_InsertKeyAssociativePointer(&Mimetypes, extension, entry, false);
return (found != NULL);
}
示例12: CreateExplain
static TRI_aql_explain_t* CreateExplain (void) {
TRI_aql_explain_t* explain;
explain = (TRI_aql_explain_t*) TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_aql_explain_t), false);
if (explain == NULL) {
return NULL;
}
explain->_count = 0;
explain->_level = 0;
explain->_result = TRI_CreateListJson(TRI_UNKNOWN_MEM_ZONE);
if (explain->_result == NULL) {
TRI_Free(TRI_UNKNOWN_MEM_ZONE, explain);
return NULL;
}
return explain;
}
示例13: TRI_InitAssociativeArray
int TRI_InitAssociativeArray (TRI_associative_array_t* array,
TRI_memory_zone_t* zone,
size_t elementSize,
uint64_t (*hashKey) (TRI_associative_array_t*, void*),
uint64_t (*hashElement) (TRI_associative_array_t*, void*),
void (*clearElement) (TRI_associative_array_t*, void*),
bool (*isEmptyElement) (TRI_associative_array_t*, void*),
bool (*isEqualKeyElement) (TRI_associative_array_t*, void*, void*),
bool (*isEqualElementElement) (TRI_associative_array_t*, void*, void*)) {
array->hashKey = hashKey;
array->hashElement = hashElement;
array->clearElement = clearElement;
array->isEmptyElement = isEmptyElement;
array->isEqualKeyElement = isEqualKeyElement;
array->isEqualElementElement = isEqualElementElement;
array->_memoryZone = zone;
array->_elementSize = (uint32_t) elementSize;
array->_nrAlloc = 0;
array->_nrUsed = 0;
if (NULL == (array->_table = static_cast<char*>(TRI_Allocate(zone, array->_elementSize * INITIAL_SIZE, true)))) {
return TRI_ERROR_OUT_OF_MEMORY;
}
array->_nrAlloc = INITIAL_SIZE;
#ifdef TRI_INTERNAL_STATS
array->_nrFinds = 0;
array->_nrAdds = 0;
array->_nrRems = 0;
array->_nrResizes = 0;
array->_nrProbesF = 0;
array->_nrProbesA = 0;
array->_nrProbesD = 0;
array->_nrProbesR = 0;
#endif
return TRI_ERROR_NO_ERROR;
}
示例14: TRI_InitMultiArray
void TRI_InitMultiArray(TRI_multi_array_t* array,
TRI_memory_zone_t* zone,
size_t elementSize,
uint64_t (*hashKey) (TRI_multi_array_t*, void*),
uint64_t (*hashElement) (TRI_multi_array_t*, void*),
void (*clearElement) (TRI_multi_array_t*, void*),
bool (*isEmptyElement) (TRI_multi_array_t*, void*),
bool (*isEqualKeyElement) (TRI_multi_array_t*, void*, void*),
bool (*isEqualElementElement) (TRI_multi_array_t*, void*, void*)) {
array->hashKey = hashKey;
array->hashElement = hashElement;
array->clearElement = clearElement;
array->isEmptyElement = isEmptyElement;
array->isEqualKeyElement = isEqualKeyElement;
array->isEqualElementElement = isEqualElementElement;
array->_memoryZone = zone;
array->_elementSize = elementSize;
array->_nrAlloc = INITIAL_SIZE;
array->_table = TRI_Allocate(array->_memoryZone, array->_elementSize * array->_nrAlloc, true);
if (array->_table == NULL) {
array->_nrAlloc = 0;
}
array->_nrUsed = 0;
#ifdef TRI_INTERNAL_STATS
array->_nrFinds = 0;
array->_nrAdds = 0;
array->_nrRems = 0;
array->_nrResizes = 0;
array->_nrProbesF = 0;
array->_nrProbesA = 0;
array->_nrProbesD = 0;
array->_nrProbesR = 0;
#endif
}
示例15: CreateShadow
static TRI_shadow_t* CreateShadow (const void* const data) {
TRI_shadow_t* shadow = (TRI_shadow_t*) TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_shadow_t), false);
if (shadow == NULL) {
return NULL;
}
shadow->_rc = 1;
shadow->_data = (void*) data;
shadow->_id = TRI_NewTickVocBase();
shadow->_deleted = false;
shadow->_type = SHADOW_TRANSIENT;
UpdateTimestampShadow(shadow);
LOG_TRACE("created shadow %p with data ptr %p and id %llu",
shadow,
data,
(unsigned long long) shadow->_id);
return shadow;
}