1
0
Fork 0

fixed memory error

This commit is contained in:
Jan Steemann 2013-01-18 17:56:38 +01:00
parent 068eaf0dd6
commit 452a266475
2 changed files with 18 additions and 16 deletions

View File

@ -25,9 +25,8 @@ v1.2.alpha (XXXX-XX-XX)
This was achieved by adding the dump() function for the "internal" object This was achieved by adding the dump() function for the "internal" object
* reduced memory usage and insertion time for edges index * reduced memory usage and insertion time for edges index
Inserting into the edges index now performs one instead of two malloc operations, Inserting into the edges index now avoids costly comparisons in case of a hash
and costly comparisons in case of a hash collisions are also avoided on insertion, collision, reducing the prefilling/loading timer for bigger edge collections
reducing the prefilling/loading timer for bigger edge collections
* added fulltext queries to AQL via FULLTEXT() function. This allows search * added fulltext queries to AQL via FULLTEXT() function. This allows search
fulltext indexes from an AQL query to find matching documents fulltext indexes from an AQL query to find matching documents

View File

@ -542,7 +542,6 @@ static bool IsEqualElementEdge (TRI_multi_pointer_t* array,
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
static int InsertEdge (TRI_index_t* idx, TRI_doc_mptr_t const* doc) { static int InsertEdge (TRI_index_t* idx, TRI_doc_mptr_t const* doc) {
TRI_edge_header_t* entries;
TRI_edge_header_t* entryIn; TRI_edge_header_t* entryIn;
TRI_edge_header_t* entryOut; TRI_edge_header_t* entryOut;
TRI_doc_edge_key_marker_t const* edge; TRI_doc_edge_key_marker_t const* edge;
@ -557,19 +556,19 @@ static int InsertEdge (TRI_index_t* idx, TRI_doc_mptr_t const* doc) {
// allocate all edge headers and return early if memory allocation fails // allocate all edge headers and return early if memory allocation fails
// use one allocation with 2 slots entryIn = TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_edge_header_t), false);
// the IN entry will be in the first slot, and we only need to free this one later if (entryIn == NULL) {
// using one allocation with 2 slots saves a lot of mallocs, and speeds up the
// index insertion for a large edge collection
entries = TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, 2 * sizeof(TRI_edge_header_t), false);
if (entries == NULL) {
return TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY); return TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY);
} }
// we have allocated all necessary memory by here entryOut = TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_edge_header_t), false);
if (entryOut == NULL) {
// OOM
TRI_Free(TRI_UNKNOWN_MEM_ZONE, entryIn);
return TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY);
}
// first slot: IN // first slot: IN
entryIn = entries;
entryIn->_mptr = doc; entryIn->_mptr = doc;
entryIn->_flags = TRI_FlagsEdge(TRI_EDGE_IN, isReflexive); entryIn->_flags = TRI_FlagsEdge(TRI_EDGE_IN, isReflexive);
entryIn->_cid = edge->_toCid; entryIn->_cid = edge->_toCid;
@ -577,7 +576,6 @@ static int InsertEdge (TRI_index_t* idx, TRI_doc_mptr_t const* doc) {
TRI_InsertElementMultiPointer(edgesIndex, entryIn, true, false); TRI_InsertElementMultiPointer(edgesIndex, entryIn, true, false);
// second slot: OUT // second slot: OUT
entryOut = entries + 1;
entryOut->_mptr = doc; entryOut->_mptr = doc;
entryOut->_flags = TRI_FlagsEdge(TRI_EDGE_OUT, isReflexive); entryOut->_flags = TRI_FlagsEdge(TRI_EDGE_OUT, isReflexive);
entryOut->_cid = edge->_fromCid; entryOut->_cid = edge->_fromCid;
@ -614,7 +612,12 @@ static int RemoveEdge (TRI_index_t* idx, TRI_doc_mptr_t const* doc) {
entry._flags = TRI_LookupFlagsEdge(TRI_EDGE_OUT); entry._flags = TRI_LookupFlagsEdge(TRI_EDGE_OUT);
entry._cid = edge->_fromCid; entry._cid = edge->_fromCid;
entry._key = ((char*) edge) + edge->_offsetFromKey; entry._key = ((char*) edge) + edge->_offsetFromKey;
TRI_RemoveElementMultiPointer(edgesIndex, &entry); old = TRI_RemoveElementMultiPointer(edgesIndex, &entry);
// the pointer to the OUT element is also the memory pointer we need to free
if (old != NULL) {
TRI_Free(TRI_UNKNOWN_MEM_ZONE, old);
}
// IN // IN
entry._flags = TRI_LookupFlagsEdge(TRI_EDGE_IN); entry._flags = TRI_LookupFlagsEdge(TRI_EDGE_IN);
@ -723,7 +726,7 @@ void TRI_DestroyEdgeIndex (TRI_index_t* idx) {
for (i = 0; i < n; ++i) { for (i = 0; i < n; ++i) {
TRI_edge_header_t* element = edgesIndex->_edges._table[i]; TRI_edge_header_t* element = edgesIndex->_edges._table[i];
if (element != NULL && (element->_flags & TRI_EDGE_BIT_DIRECTION_IN) != 0) { if (element != NULL) {
TRI_Free(TRI_UNKNOWN_MEM_ZONE, element); TRI_Free(TRI_UNKNOWN_MEM_ZONE, element);
} }
} }