memory-management

Memory-efficient C++ strings (interning, ropes, copy-on-write, etc) [closed]

给你一囗甜甜゛ 提交于 2019-12-28 03:38:14
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . My application is having memory problems, including copying lots of strings about, using the same strings as keys in lots of hashtables, etc. I'm looking for a base class for my strings that makes this very efficient. I'm hoping for: String interning (multiple strings of the same value use the same memory), copy

How do realloc and memcpy work?

旧街凉风 提交于 2019-12-28 03:35:08
问题 I have two questions. Do realloc() and memcpy() copy the entries in an array to another in a way faster than just iterating on each element O(N) ? If the answer is yes then what do you think is its complexity ? If the size allocated is smaller than the original size, does realloc() copy the entries to somewhere else or just leave them as they are decreasing the size of the array ? 回答1: 1 - No. They copy a block at a time. See http://www.embedded.com/design/configurable-systems/4024961

Objective c, Memory management of instance members

℡╲_俬逩灬. 提交于 2019-12-28 03:11:26
问题 I am confuzed by the memory management of instance members. I have a class with a ivar: DetailedResultsTableViewController *detailedResultsTableViewController; and @property (nonatomic, retain) DetailedResultsTableViewController *detailedResultsTableViewController; in the .m file: @synthesize detailedResultsTableViewController; and [detailedResultsTableViewController release]; When I initial this variable: self.detailedResultsMapViewController = [[DetailedResultsMapViewController alloc]

Is it possible to debug “Terminated due to memory error”?

空扰寡人 提交于 2019-12-27 23:39:50
问题 In a certain (consistent) point when my app is running, I consistently get the xcode error message Terminated due to memory error. I cannot find the code causing the error, but I can tell what code is near the error (using breakpoints). The error is caused directly after returning a certain cell in my implemenation of the - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath UITableViewDataSource delegate method. I can confirm that it is

Why does this program crash: passing of std::string between DLLs

假装没事ソ 提交于 2019-12-27 20:07:21
问题 I have some trouble figuring out why the following crashes (MSVC9): //// the following compiles to A.dll with release runtime linked dynamically //A.h class A { __declspec(dllexport) std::string getString(); }; //A.cpp #include "A.h" std::string A::getString() { return "I am a string."; } //// the following compiles to main.exe with debug runtime linked dynamically #include "A.h" int main() { A a; std::string s = a.getString(); return 0; } // crash on exit Obviously (?) this is due to the

Fields of class, are they stored in the stack or heap?

99封情书 提交于 2019-12-27 19:12:10
问题 I saw a question yesterday which raised (for me) another question. Please look at the following code: public class Class1 { int A; //as I uderstand, int is value type and therefore lives in the stack } class Class2 { Run() { Class1 instance1 = new Class1(); instance1.A = 10; //it points to value type, but isnt this reference (on heap)? } } Or while creating the instance of Class1, its field types are created on the heap as well? But then I do not understand when it would really be on the

will two strings with same content be stored in the same memory location?

余生颓废 提交于 2019-12-27 14:54:08
问题 This is a question that I got in an interview. I've two strings defined as String s1="Java"; String s2="Java"; My question is whether these two references point to the same memory location. In general, when we create identical strings (without new keyword), does the content get stored in the memory only once and all the String objects with the same content just refer to the same location, without storing the string "Java" redundantly ? The hash codes of s1 and s2 are the same. But are

iOS 7 Sprite Kit freeing up memory

一个人想着一个人 提交于 2019-12-27 11:59:38
问题 I am building an iOS game aimed for the new iOS 7 and Sprite Kit, using emitter nodes and physics to enhance gameplay. While developing the app, I ran into a serious problem: you create your scenes, nodes, effects, but when you are done and need to return to the main screen, how do you free up all the memory allocated by these resources? Ideally ARC should free up everything and the application should get back to the memory consumption level it had before creating the scene, but this is not

iOS 5 Best Practice (Release/retain?)

﹥>﹥吖頭↗ 提交于 2019-12-27 11:33:08
问题 As a beginning iPhone programmer, what is the best practice for writing apps to be used either with iOS 5 or older versions? Specifically, should I continue using the release/retain of data, or should I ignore that? Does it matter? 回答1: It's up to you. You can write apps using ARC (Automatic Reference Counting), and Xcode will write "glue code" to allow your ARC enabled apps to run on iOS 4, no modifications required. However, certain things wont work, and most noticeably many libraries you

iOS 5 Best Practice (Release/retain?)

扶醉桌前 提交于 2019-12-27 11:33:08
问题 As a beginning iPhone programmer, what is the best practice for writing apps to be used either with iOS 5 or older versions? Specifically, should I continue using the release/retain of data, or should I ignore that? Does it matter? 回答1: It's up to you. You can write apps using ARC (Automatic Reference Counting), and Xcode will write "glue code" to allow your ARC enabled apps to run on iOS 4, no modifications required. However, certain things wont work, and most noticeably many libraries you