Hello All,
I am learning C++. I am trying to learn this dynamic memory allocation. In the below code I am trying to allocate memory using malloc and realloc.
int main (void) {
char *g = (char*) malloc (sizeof(char) * 2);
g = "ab";
g = (char*) realloc (g, sizeof(char) * 200);
strcpy (g, "cdefg");
cout << g << endl;
return 0...
I'm trying to run the following program, which calculates roots of polynomials of degree up to d with coefficients only +1 or -1, and then store it into files.
d = 20; n = 18000;
f[z_, i_] := Sum[(2 Mod[Floor[(i - 1)/2^k], 2] - 1) z^(d - k), {k, 0, d}];
Here f[z,i] gives a polynomial in z with plus or minus signs counting in binary. ...
There are many Cocoa methods that require an NSError object as a parameter to a method, but are really a means of returning an error object to the calling method if errors exist. Is this returned object retained? That is, in the calling object code (the method to which the error is returned), does there need to be some code like:
NSEr...
Hi,
Memory management is a very important issue in iPhone. So I am asking a very general question.
There are two ways to call a the viewController of another class.
Way 1:
AnotherClassViewController *viewController = [[[AnotherClassViewController alloc] initWithNibName:@"AnotherClassView" bundle:nil] autorelease];
[self.navigationCo...
I am programming my first iPhone app (which crashes with an EXC BAD ACCESS error).
I've read a few other similar answers, but still don't have a clear picture of how to fix my code.
Can someone help fix my memory management for the UITableViewCell *cell object in this snippet:
- (UITableViewCell *)tableView:(UITableView *)tableView ce...
I've allocated a chuck of memory with char* memoryChunk = malloc ( 80* sizeof(char) + 1); What is keeping me from writing into the memory location beyond 81 units? What can I do to prevent that?
void testStage2(void) {
char c_str1[20] = "hello";
char* ut_str1;
char* ut_str2;
printf("Starting stage 2 tests\n");
strcat(c_str1, " wor...
Hi i want to know the difference between drain, release,dealloc and retain in Objective-C.
...
It's said that Python automatically manages memory. I'm confused because I have a Python program consistently uses more than 2GB of memory.
It's a simple multi-thread binary data downloader and unpacker.
def GetData(url):
req = urllib2.Request(url)
response = urllib2.urlopen(req)
data = response.read() // data size is about...
How can I minimize the footprint of a website built using MVC. My application currently runs at around 20mb, I'd like to reduce it if possible.
Edit: I've switched hosts, problem solved.
...
I'm declaring an NSString property in a class and objective-c is complaining that:
NSString no 'assign', 'retain', or 'copy' attribute is specified
It then casually lets me know that "assign is used instead".
Can someone explain to me the difference between assign, retain and copy in terms of normal C memory management functions?
...
Okay, here's the setup: I work in HPC, and we're preparing for the need to scale up to tens of thousands of nodes. To deal with this, I've implemented a local process that caches information on each node to reduce the amount of network traffic. It then exposes this information via shared-memory. The basic logic is that there is one well-...
What is the most memory efficient way to loop through an NSMutableArray of custom objects?
I need to check a value in each object in the array and return how many of that type of object is in the array.
...
Hi, am pretty excited with the GNU Debugger and a GUI called Insight as it has saved me A LOT OF time. Thus I am posting this question/answer for other newbies out there like me having problems with their C code looking for a visual way to see what's going on.
I am working on Linux Mint (Ubuntu) btw.
...
I'm having an out of memory error. I have a large range of inputs (2^40), that is too large to hold at once. Each input is a String[].
Instead, I thought I'd run my test program on each input, write the results to a file, then discard the input. The length of the longest input is 42, so that isn't an error causing the overflow. I don't...
In the section titled 'Memory Warnings' here http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmNibObjects.html, I don't follow why the IBOutlet is set to nil in the dealloc. If
self.anOutlet = nil
causes a crash as mentioned in the topic, why are they setting the ivar to nil?
In general, ...
Hi,
I'm having trouble with memory fragmentation in my program and not being able to allocate very large memory blocks after a while. I've read the related posts on this forum - mainly this one. And I still have some questions.
I've been using a memory space profiler to get a picture of the memory. I wrote a 1 line program that conta...
This is on the iPhone.
So what if I have a function like
- (SomeObject*)buildObject;
Do I need to pass in a variable that I have already alloc'd outside like
- (void)assignObject(SomeObject** out);
Or can I do
- (SomeObject*)buildObject
{
return [[[SomeObject alloc] init] autorelease];
}
and use it like
SomeObject* obj = [[...
I'm getting a segmentation fault the first time I call malloc() after I protect a memory region with mprotect(). This is a code sniplet that does the memory allocation the the protection:
#define PAGESIZE 4096
void* paalloc(int size){ // Allocates and aligns memory
int type_size = sizeof(double);
void* p;
p = ...
I'm ready about Memory management in C# from the book "Professional C#"
The presence of the garbage collector
means that you will usually not worry
about objects that you no longer need;
you will simply allow all references
to those objects to go out of scope
and allow the garbage collector to
free memory as required. How...
When, I run my application in the simulator using the Leaks instrument, it uses about 2.5mb of memory. When I run it on the iPhone, it takes forever to launch, slowly climbs to ~34mb of memory and then crashes. However, when I run it on the iPhone without Leaks, it launches quickly and runs fine. Why is this?
...