jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed, long max_bytes_needed, long already_allocated) { long limit = cinfo->mem->max_memory_to_use - already_allocated; __boundcheck_metadata_store((void *)(&limit),(void *)((size_t)(&limit)+sizeof(limit)*8-1)); long slop; __boundcheck_metadata_store((void *)(&slop),(void *)((size_t)(&slop)+sizeof(slop)*8-1)); long mem; __boundcheck_metadata_store((void *)(&mem),(void *)((size_t)(&mem)+sizeof(mem)*8-1)); /* Don't ask for more than what application has told us we may use */ if (max_bytes_needed > limit && limit > 0) max_bytes_needed = limit; /* Find whether there's a big enough free block in the heap. * CompactMem tries to create a contiguous block of the requested size, * and then returns the size of the largest free block (which could be * much more or much less than we asked for). * We add some slop to ensure we don't use up all available memory. */ slop = max_bytes_needed / 16 + 32768L; mem = CompactMem(max_bytes_needed + slop) - slop; if (mem < 0) mem = 0; /* sigh, couldn't even get the slop */ /* Don't take more than the application says we can have */ if (mem > limit && limit > 0) mem = limit; return mem; }
void free_and_unlock_memory(void) { SoundManager::instance()->StopAllSounds(); #ifdef mac PurgeMem(maxSize); CompactMem(maxSize); #endif }