memory-management

Will new return NULL in any case?

不问归期 提交于 2019-12-27 10:54:20
问题 I know that according to C++ standard in case the new fails to allocate memory it is supposed to throw std::bad_alloc exception. But I have heard that some compilers such as VC6 (or CRT implementation?) do not adhere to it. Is this true ? I am asking this because checking for NULL after each and every new statement makes code look very ugly. 回答1: VC6 was non-compliant by default in this regard. VC6's new returned 0 (or NULL ). Here's Microsoft's KB Article on this issue along with their

Explanation of strong and weak storage in iOS5

爷,独闯天下 提交于 2019-12-27 10:37:33
问题 I am new to iOS5 development and using objective-c. I have trouble understanding the difference between strong and weak storage. I have read the documentation and other SO questions, but they all sound identical to me with no further insight. I read the documentation: Transitioning To ARC - it references to iOS4 terms of retain, assign, and release; which confuses me. Then I look into Open U CS193p, where it differentiates strong and weak: Strong : "keep this in the heap until I don't point

Why would you use an ivar?

落花浮王杯 提交于 2019-12-27 10:36:07
问题 I usually see this question asked the other way, such as Must every ivar be a property? (and I like bbum's answer to this Q). I use properties almost exclusively in my code. Every so often, however, I work with a contractor who has been developing on iOS for a long time and is a traditional game programmer. He writes code that declares almost no properties whatsoever and leans on ivars. I assume he does this because 1.) he's used to it since properties didn't always exist until Objective C 2

Why would you use an ivar?

浪尽此生 提交于 2019-12-27 10:35:40
问题 I usually see this question asked the other way, such as Must every ivar be a property? (and I like bbum's answer to this Q). I use properties almost exclusively in my code. Every so often, however, I work with a contractor who has been developing on iOS for a long time and is a traditional game programmer. He writes code that declares almost no properties whatsoever and leans on ivars. I assume he does this because 1.) he's used to it since properties didn't always exist until Objective C 2

Explanation of strong and weak storage in iOS5

蹲街弑〆低调 提交于 2019-12-27 10:35:28
问题 I am new to iOS5 development and using objective-c. I have trouble understanding the difference between strong and weak storage. I have read the documentation and other SO questions, but they all sound identical to me with no further insight. I read the documentation: Transitioning To ARC - it references to iOS4 terms of retain, assign, and release; which confuses me. Then I look into Open U CS193p, where it differentiates strong and weak: Strong : "keep this in the heap until I don't point

Peak memory usage of a linux/unix process

那年仲夏 提交于 2019-12-27 10:28:14
问题 Is there a tool that will run a command-line and report the peak RAM usage total? I'm imagining something analogous to /usr/bin/time 回答1: Here's a one-liner that doesn't require any external scripts or utilities and doesn't require you to start the process via another program like Valgrind or time, so you can use it for any process that's already running: grep VmPeak /proc/$PID/status (replace $PID with the PID of the process you're interested in) 回答2: [ Edit : Works on Ubuntu 14.04: /usr/bin

Does GC release back memory to OS?

徘徊边缘 提交于 2019-12-27 08:54:07
问题 When the garbage collector runs and releases memory does this memory go back to the OS or is it being kept as part of the process. I was under the strong impression that the memory is never actually released back to OS but kept as part of the memory area/pool to be reused by the same process. As a result the actual memory of a process would never decrease. An article that reminded me was this and Java’s Runtime is written in C/C++ so I guess the same thing applies? Update My question is about

Why can freed dynamically allocated memory still be accessed after a delete operation in C++?

偶尔善良 提交于 2019-12-26 06:49:13
问题 Suppose I have allocated some memory for storing an int value like this: int *p=new int; Here I created the required memory using new operator and assigned the address of that memory block so that I can access that memory block. Now it's my control to what I store in that memory block. But when I write a statement like this: delete p; we say that I have deleted the dynamically allocated memory. But if I really delete 'd or freed up that memory, should I not be able to access that memory

Why can freed dynamically allocated memory still be accessed after a delete operation in C++?

こ雲淡風輕ζ 提交于 2019-12-26 06:49:07
问题 Suppose I have allocated some memory for storing an int value like this: int *p=new int; Here I created the required memory using new operator and assigned the address of that memory block so that I can access that memory block. Now it's my control to what I store in that memory block. But when I write a statement like this: delete p; we say that I have deleted the dynamically allocated memory. But if I really delete 'd or freed up that memory, should I not be able to access that memory

C++ - destructors [closed]

走远了吗. 提交于 2019-12-25 21:09:10
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 8 years ago . In the external C++ learning resource that I'm reading. What is an example on this statement? When a variable goes out of scope, or a dynamically allocated variable is explicitly deleted using the delete keyword,