library/src/memory_profiling/BP_LibraryMemoryProfiling.cc
// removes a chunk if it's been bpfree'd
// removes a chunk from update
removes a chunk if it's been bpfree'd
removes a chunk from update
removes a chunk if it ' s been bpfree ' d removes a chunk from update
BP_ERROR_T BP_MemProfilerRemoveChunk(void * addr)
{
#if DEBUG_MEMORY_PROFILER == 1
	printf("\n [!!] Attempting to remove monitored chunk: %p", addr);
#endif
	if(!addr)
		return ERR_FAILURE;
	P_BP_MEMPROF_ENTRY new_entries = (P_BP_MEMPROF_ENTRY) bpcalloc(1, sizeof(BP_MEMPROF_ENTRY) * (global_memprof_pool_n - 1));
	if(!new_entries)
		return ERR_FAILURE;
#if DEBUG_MEMORY_PROFILER == 1
	printf("\n [!!] Attempting to find chunk in monitored chunk list: %p", addr);
#endif
	size_t n = 0;
	for(; n < global_memprof_pool_n; n++)
	{
		if(global_memprof_pool[n].mem_ptr == addr)
		{
			#if DEBUG_MEMORY_PROFILER == 1
				printf("\n [!!] Found our chunk %p at entry index %u (struct addr: %p)", addr, n, (void *) &global_memprof_pool[n]);
			#endif
			size_t entries_offset   = n;
			size_t following_offset = n+1;
			size_t remaining_entries = (global_memprof_pool_n - n - 1);
			memcpy((void *)new_entries, (void *) global_memprof_pool, sizeof(BP_MEMPROF_ENTRY) * n);
			memcpy((void *)&new_entries[n], (void *) &global_memprof_pool[n+1], sizeof(BP_MEMPROF_ENTRY) * remaining_entries);
			global_memprof_pool = new_entries;
			#if DEBUG_MEMORY_PROFILER == 1
				printf("\n [!!] Chunk %p has been removed from the list.", addr);
			#endif
			break;
		}
	}
	global_memprof_pool_n--;
	return ERR_SUCCESS;
}
BP_ERROR_T BP_MemProfilerRemoveChunk ( void * addr ) { #if DEBUG_MEMORY_PROFILER == 1 printf ( " \n " , addr ) ; #endif if ( ! addr ) return ERR_FAILURE ; P_BP_MEMPROF_ENTRY new_entries = ( P_BP_MEMPROF_ENTRY ) bpcalloc ( 1 , sizeof ( BP_MEMPROF_ENTRY ) * ( global_memprof_pool_n - 1 ) ) ; if ( ! new_entries ) return ERR_FAILURE ; #if DEBUG_MEMORY_PROFILER == 1 printf ( " \n " , addr ) ; #endif size_t n = 0 ; for ( ; n < global_memprof_pool_n ; n ++ ) { if ( global_memprof_pool [ n ] . mem_ptr == addr ) { #if DEBUG_MEMORY_PROFILER == 1 printf ( " \n " , addr , n , ( void * ) & global_memprof_pool [ n ] ) ; #endif size_t entries_offset = n ; size_t following_offset = n + 1 ; size_t remaining_entries = ( global_memprof_pool_n - n - 1 ) ; memcpy ( ( void * ) new_entries , ( void * ) global_memprof_pool , sizeof ( BP_MEMPROF_ENTRY ) * n ) ; memcpy ( ( void * ) & new_entries [ n ] , ( void * ) & global_memprof_pool [ n + 1 ] , sizeof ( BP_MEMPROF_ENTRY ) * remaining_entries ) ; global_memprof_pool = new_entries ; #if DEBUG_MEMORY_PROFILER == 1 printf ( " \n " , addr ) ; #endif break ; } } global_memprof_pool_n -- ; return ERR_SUCCESS ; }
removes a chunk if it's been bpfree'd
removes a chunk from update
removes a chunk if it ' s been bpfree ' d removes a chunk from update
// cant remove what isn't there // set the new entries // get chunk index // set offset // copy in the first half of the stack // copy in the remaining entries // set pool to the new stack // break the loop // decrement element count in the pool // return indicating success