MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / _memory_heap_cache_insert

Function _memory_heap_cache_insert

vm/ByteCodeTranslator/src/rpmalloc.c:938–975  ·  view source on GitHub ↗

Insert span into thread cache, releasing to global cache if overflow

Source from the content-addressed store, hash-verified

936
937//! Insert span into thread cache, releasing to global cache if overflow
938static void
939_memory_heap_cache_insert(heap_t* heap, span_t* span, size_t page_count) {
940#if MAX_SPAN_CACHE_DIVISOR == 0
941 (void)sizeof(heap);
942 _memory_global_cache_insert(span, 1, page_count);
943#else
944 size_t span_class_idx = _span_class_from_page_count(page_count);
945 span_t** cache = &heap->span_cache[span_class_idx];
946 span->next_span = *cache;
947 if (*cache)
948 span->data.list_size = (*cache)->data.list_size + 1;
949 else
950 span->data.list_size = 1;
951 *cache = span;
952#if MAX_SPAN_CACHE_DIVISOR > 1
953 //Check if cache exceeds limit
954 if ((span->data.list_size >= (MIN_SPAN_CACHE_RELEASE + MIN_SPAN_CACHE_SIZE)) &&
955 (span->data.list_size > heap->span_counter[span_class_idx].cache_limit)) {
956 //Release to global cache
957 count_t list_size = 1;
958 span_t* next = span->next_span;
959 span_t* last = span;
960 while (list_size < MIN_SPAN_CACHE_RELEASE) {
961 last = next;
962 next = next->next_span;
963 ++list_size;
964 }
965 next->data.list_size = span->data.list_size - list_size;
966 last->next_span = 0; //Terminate list
967 *cache = next;
968 _memory_global_cache_insert(span, list_size, page_count);
969#if ENABLE_STATISTICS
970 heap->thread_to_global += list_size * page_count * PAGE_SIZE;
971#endif
972 }
973#endif
974#endif
975}
976
977//! Deallocate the given small/medium memory block from the given heap
978static void

Callers 2

Calls 2

Tested by

no test coverage detected