MCPcopy Create free account
hub / github.com/EasyRPG/Player / FreeCacheMemory

Function FreeCacheMemory

src/audio_secache.cpp:40–68  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38 int cache_size = 0;
39
40 void FreeCacheMemory() {
41 auto cur_time = Game_Clock::GetFrameTime();
42
43 for (auto it = cache.begin(); it != cache.end(); ) {
44 if (it->second.use_count() > 1) {
45 // SE is currently playing
46 ++it;
47 continue;
48 }
49
50 if (cache_size <= cache_limit && cur_time - it->second->last_access < 3s) {
51 // Below memory limit and last access < 3s
52 ++it;
53 continue;
54 }
55
56#ifdef CACHE_DEBUG
57 Output::Debug("SE: Freeing memory of {}", it->first);
58#endif
59
60 cache_size -= it->second->buffer.size();
61
62 it = cache.erase(it);
63 }
64
65#ifdef CACHE_DEBUG
66 Output::Debug("SE cache size: {}", cache_size / 1024.0 / 1024);
67#endif
68 }
69}
70
71std::unique_ptr<AudioSeCache> AudioSeCache::Create(Filesystem_Stream::InputStream stream, std::string_view name) {

Callers 1

CreateSeDecoderMethod · 0.85

Calls 3

beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected