memory-management

Getting dynamically allocated array size

僤鯓⒐⒋嵵緔 提交于 2020-01-01 16:58:07
问题 In "The C++ Programming Language" book Stroustrup says: "To deallocate space allocated by new , delete and delete[] must be able to determine the size of the object allocated. This implies that an object allocated using the standard implementation of new will occupy slightly more space than a static object. Typically, one word is used to hold the object’s size. That means every object allocated by new has its size located somewhere in the heap. Is the location known and if it is how can I

Swift : How to handle a lot of textures in memory

*爱你&永不变心* 提交于 2020-01-01 16:48:10
问题 I have a lot of characters in my game and because of that I have so many textures. When a texture atlas is loaded (containing about 5 different image textures) it increases the memory use and keeps it there at that amount. So the more textures just keeps driving that number up and up until sometimes the application crashes. I don't need all the characters at once, how can i maybe load some character textures when I need them and deallocate the others when i don't, but ill need to be able to

Wrapping C++ dynamic array with Python+ctypes, segfault

醉酒当歌 提交于 2020-01-01 14:39:58
问题 I wanted to wrap a small C++ code allocating an array with ctypes and there is something wrong with storing the address in a c_void_p object. (Note: the pointers are intentionally cast to void* , 'cause later I want to do the allocation the same way for arrays of C++ objects, too.) The C(++) functions to be wrapped: void* test_alloc() { const int size = 100000000; int* ptr = new int[size]; std::cout << "Allocated " << size * sizeof(int) << " bytes @ " << ptr << std::endl; return static_cast

Wrapping C++ dynamic array with Python+ctypes, segfault

删除回忆录丶 提交于 2020-01-01 14:38:32
问题 I wanted to wrap a small C++ code allocating an array with ctypes and there is something wrong with storing the address in a c_void_p object. (Note: the pointers are intentionally cast to void* , 'cause later I want to do the allocation the same way for arrays of C++ objects, too.) The C(++) functions to be wrapped: void* test_alloc() { const int size = 100000000; int* ptr = new int[size]; std::cout << "Allocated " << size * sizeof(int) << " bytes @ " << ptr << std::endl; return static_cast

App crashes on launch with < 256 RAM iOS Devices

纵饮孤独 提交于 2020-01-01 12:11:24
问题 The Info I recently launched an app on the AppStore. After testing on the simulator thousands of times, and actual devices hundreds of times we finally released our app. The Problem Reviews started popping up about app crashes when the user launches the app. We figured that the app crashes on launch on iOS devices with less than (or equal to) 256 Mb of RAM . The following devices are devices our app supports with less than 256: iPod Touch 4G iPhone 3GS iPad 1 The app doesn't always crash.

App crashes on launch with < 256 RAM iOS Devices

别来无恙 提交于 2020-01-01 12:11:13
问题 The Info I recently launched an app on the AppStore. After testing on the simulator thousands of times, and actual devices hundreds of times we finally released our app. The Problem Reviews started popping up about app crashes when the user launches the app. We figured that the app crashes on launch on iOS devices with less than (or equal to) 256 Mb of RAM . The following devices are devices our app supports with less than 256: iPod Touch 4G iPhone 3GS iPad 1 The app doesn't always crash.

How do I save space with inverted page tables?

巧了我就是萌 提交于 2020-01-01 11:54:08
问题 Why do we save memory if we use inverted page tables to map virtual addresses to physical ones? If we have for example two processes which both have 4 pages we would have 8 entries in two different tables pointing from virtual to physical address: Process 1: [0] = 1 [1] = 5 [2] = 63 [3] = 0 Process 2: [20] = 14 [21] = 55 [22] = 11 [25] = 9 If we would use inverted page tables we would only have one big table pointing it the other way around. But in size they equal. 2) Inverted page table [0]

NSAutoreleasePool. When is it appropriate to create a new autorelease pool?

拟墨画扇 提交于 2020-01-01 10:56:25
问题 On iOS/CocoaTouch I often see code that creates a new instance of NSAutoreleasePool within a method. I recently saw one within an NSOperation. What are the ground rules for setting up a new instance of NSAutoreleasePool? Why is this preferable to simply relying on the pre-existing release pool created in main.m? Thanks, Doug 回答1: You can use a new autorelease pool whenever you want, but it is not always beneficial. It is required whenever you start a new thread or objects autoreleased in that

How to overcome memory constraints using foreach

大憨熊 提交于 2020-01-01 10:12:34
问题 I am trying to process > 10000 xts objects saved on disk each being around 0.2 GB when loaded into R. I would like to use foreach to process these in parallel. My code works for something like 100 xts objects which I pre-load in memory, export etc. but after > 100 xts objects I hit memory limits on my machine. Example of what I am trying to do: require(TTR) require(doMPI) require(foreach) test.data <- runif(n=250*10*60*24) xts.1 <- xts(test.data, order.by=as.Date(1:length(test.data))) xts.1 <

How do I create a local autorelease pool to save up memory?

删除回忆录丶 提交于 2020-01-01 09:59:50
问题 Apple says that this is a good idea for saving memory. What would that look like in code? 回答1: Usualy you don't need to create autorelease pool, because system cares about this. But, sometimes you need to do this. It's usualy in big loops. Code would look like this: NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; int i; for (i = 0; i < 1000000; i++) { id object = [someArray objectAtIndex:i]; // do something with object if (i % 1000 == 0) { [pool release]; pool = [