src/hbcore/core/hbsharedmemoryallocators_p.h
changeset 28 b7da29130b0e
parent 23 e6ad4ef83b23
equal deleted inserted replaced
23:e6ad4ef83b23 28:b7da29130b0e
    37 
    37 
    38 // threshold for allocs going to sub allocator and main allocator
    38 // threshold for allocs going to sub allocator and main allocator
    39 static const int MAXIMUM_ALLOC_SIZE_FOR_SUBALLOCATOR = 224;
    39 static const int MAXIMUM_ALLOC_SIZE_FOR_SUBALLOCATOR = 224;
    40 
    40 
    41 // used to identify memory allocated by main or sub allocator
    41 // used to identify memory allocated by main or sub allocator
    42 // if metadata (integer just before allocated data) & MAIN_ALLOCATOR_IDENTIFIER
    42 // if metadata (qptrdiff just before allocated data) & MAIN_ALLOCATOR_IDENTIFIER
    43 // == true, data was allocated using main allocator, otherwise suballocator
    43 // == true, data was allocated using main allocator, otherwise suballocator
    44 // was used
    44 // was used. This works because suballocator saves aligned offsets to metadata and
    45 static const int MAIN_ALLOCATOR_IDENTIFIER = 0x80000000;
    45 // they can't be odd.
       
    46 static const qptrdiff MAIN_ALLOCATOR_IDENTIFIER = 1;
    46 
    47 
    47 // max. amount of different chunk sizes in multisegment allocator
    48 // max. amount of different chunk sizes in multisegment allocator
    48 static const int AMOUNT_OF_DIFFERENT_CHUNK_SIZES = 8;
    49 static const int AMOUNT_OF_DIFFERENT_CHUNK_SIZES = 8;
    49 
    50 
    50 
    51 
   126     {
   127     {
   127         TreeNode lengthNode;
   128         TreeNode lengthNode;
   128         TreeNode pointerNode;
   129         TreeNode pointerNode;
   129         quintptr next;
   130         quintptr next;
   130         quintptr prev;
   131         quintptr prev;
   131         int allocatorIdentifier;
   132         qptrdiff allocatorIdentifier;
   132     };
   133     };
   133 
   134 
   134     struct HeapHeader
   135     struct HeapHeader
   135     {
   136     {
   136         quintptr identifier;
   137         quint32 identifier;
   137         quintptr lengthNode;
   138         quintptr lengthNode;
   138         quintptr pointerNode;
   139         quintptr pointerNode;
   139         int freeBytes;
   140         int freeBytes;
   140         int allocatedBytes;
   141         int allocatedBytes;
   141     };
   142     };
   182 #endif
   183 #endif
   183 
   184 
   184 private:
   185 private:
   185     struct MultiAllocatorHeader
   186     struct MultiAllocatorHeader
   186     {
   187     {
   187         quintptr identifier;
   188         quint32 identifier;
   188         // always points to the first list
   189         // always points to the first list
   189         qptrdiff offsetsToChunkLists[AMOUNT_OF_DIFFERENT_CHUNK_SIZES];
   190         qptrdiff offsetsToChunkLists[AMOUNT_OF_DIFFERENT_CHUNK_SIZES];
   190         // always points to the list with free chunks
   191         // always points to the list with free chunks
   191         qptrdiff offsetsToFreeChunkLists[AMOUNT_OF_DIFFERENT_CHUNK_SIZES];
   192         qptrdiff offsetsToFreeChunkLists[AMOUNT_OF_DIFFERENT_CHUNK_SIZES];
   192     };
   193     };