All Questions

818
votes
20answers
238732 views

Can a local variable's memory be accessed outside its scope?

I have the following code. int * foo() { int a = 5; return &a; } int main() { int* p = foo(); cout << *p; *p = 8; cout << *p; } And the code is just running...
6650
votes
25answers
1152405 views

What and where are the stack and heap?

Programming language books explain that value types are created on the stack, and reference types are created on the heap, without explaining what these two things are. I haven't read a clear explanat...
307
votes
21answers
134479 views

What uses are there for "placement new"?

Has anyone here ever used C++'s "placement new"? If so, what for? It looks to me like it would only be useful on memory-mapped hardware.
722
votes
7answers
271300 views

How do I discover memory usage of my application in Android?

How can I find the memory used on my Android application, programmatically? I hope there is a way to do it. Plus, how do I get the free memory of the phone too?
93
votes
9answers
20522 views

When and why will an OS initialise memory to 0xCD, 0xDD, etc. on malloc/free/new/delete?

I know that the OS will sometimes initialise memory with certain patterns such as 0xCD and 0xDD. What I want to know is when and why this happens. When Is this specific to the compiler used? Do ma...
100
votes
10answers
21183 views

When to use -retainCount?

I would like to know in what situation did you use -retainCount so far, and eventually the problems that can happen using it. Thanks.
98
votes
11answers
236823 views

How do you allow spaces to be entered using scanf?

Using the following code: char *name = malloc(sizeof(char) + 256); printf("What is your name? "); scanf("%s", name); printf("Hello %s. Nice to meet you.\n", name); A user can enter their name bu...
541
votes
8answers
154818 views

Which Python memory profiler is recommended?

I want to know the memory usage of my Python application and specifically want to know what code blocks/portions or objects are consuming most memory. Google search shows a commercial one is Python Me...
633
votes
4answers
1047264 views

What are the Xms and Xmx parameters when starting JVMs?

Please explain the use of Xms and Xmx parameters in JVMs. What are the default values for them?
701
votes
17answers
85938 views

Why should C++ programmers minimize use of 'new'?

I stumbled upon Stack Overflow question Memory leak with std::string when using std::list<std::string>, and one of the comments says this: Stop using new so much. I can't see any reason you ...

Previous Next