Created
March 5, 2019 07:49
-
-
Save n-suudai/1a95cf27cbe705ad57df894b9fb8af85 to your computer and use it in GitHub Desktop.
IOSメモリ追跡
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 要求されたサイズのメモリを割り当てる関数 | |
static void* FApplePlatformAllocatorAllocate(CFIndex AllocSize, CFOptionFlags Hint, void* Info) | |
{ | |
// カスタム実装 | |
void* Mem = FMemory::Malloc(AllocSize, 16); | |
return Mem; | |
} | |
// 既存のメモリブロックに要求されたサイズのメモリを再割り当てする関数 | |
static void* FApplePlatformAllocatorReallocate(void* Ptr, CFIndex Newsize, CFOptionFlags Hint, void* Info) | |
{ | |
// カスタム実装 | |
void* Mem = FMemory::Realloc(Ptr, Newsize, 16); | |
return Mem; | |
} | |
// 与えられたメモリブロックの割り当てを解除する関数 | |
static void FApplePlatformAllocatorDeallocate(void* Ptr, void* Info) | |
{ | |
// カスタム実装 | |
return FMemory::Free(Ptr); | |
} | |
// 要求を満たすのに十分な空きメモリがあるかどうかを判断する | |
static CFIndex FApplePlatformAllocatorPreferredSize(CFIndex Size, CFOptionFlags Hint, void* Info) | |
{ | |
// カスタム実装 | |
return FMemory::QuantizeSize(Size); | |
} | |
void ConfigureDefaultCFAllocator() | |
{ | |
// Configure CoreFoundation's default allocator to use our allocation routines too. | |
// https://developer.apple.com/documentation/corefoundation/cfallocatorcontext?language=objc | |
CFAllocatorContext AllocatorContext; | |
AllocatorContext.version = 0; | |
AllocatorContext.info = nullptr; | |
AllocatorContext.retain = nullptr; | |
AllocatorContext.release = nullptr; | |
AllocatorContext.copyDescription = nullptr; | |
AllocatorContext.allocate = &FApplePlatformAllocatorAllocate; | |
AllocatorContext.reallocate = &FApplePlatformAllocatorReallocate; | |
AllocatorContext.deallocate = &FApplePlatformAllocatorDeallocate; | |
AllocatorContext.preferredSize = &FApplePlatformAllocatorPreferredSize; | |
CFAllocatorRef Alloc = CFAllocatorCreate(kCFAllocatorDefault, &AllocatorContext); | |
CFAllocatorSetDefault(Alloc); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment