memory-management

Malloc on a struct containing a std::vector

时光毁灭记忆、已成空白 提交于 2020-02-14 12:11:34
问题 Here is the situation : I use a malloc to allocate memory for a struct. The struct contains various items such as pointers, string variables and vectors. The fact is, when we use malloc, no constructors are called. Using a code similar to the following one, I've experienced some situation where some variables worked while others didn't. Note : The following code doesn't compile. It's purpose is only to illustrate the situation. struct MyStruct { MyClass* mFirstClass; bool mBool; std::string

Does free() free the memory immediately

雨燕双飞 提交于 2020-02-08 03:51:04
问题 In my program, I am using malloc to allocate large amounts of memory (several hundred mbs, in chunks of say 25mb to 75mb at a time), I am subsequently freeing some of the chunks, then again reallocating some more. My question is when I use free() to free memory, does it immediately free the concerned block of memory, or it merely marks it for freeing. If it is merely marking for freeing later, is there some standard C library function to force it to be freed immediately. I am actually

YAJL memory leak problem array

余生颓废 提交于 2020-02-07 06:46:31
问题 I am trying to fetch JSON data every 2 seconds and pass it to another class for processing, everything works fine but the below code seems to have memory leaks (from Instruments) but I cannot figure out what is wrong and how I can fix, can someone please advise ??? * Updated with the full logic and it looks like the array that is passed on to the main method is leaking and Instruments is falsely reporting that as YAJL leak..(not very sure thou) * @property (nonatomic,retain,readwrite)

Contiguous blocks of memory and VM

六月ゝ 毕业季﹏ 提交于 2020-02-06 01:35:55
问题 I was reading up on Virtual Memory and from what I understand is that each process has its own VM table that maps VM addresses to Physical Addresses in real memory. So if a process allocated objects continuously they can potentially be stored in completely different places in Physical Memory. My question is that if I allocate and array which is supposed to be stored in a contiguous block of memory and if the size of the array requires more space than one page can provide, from what I

Contiguous blocks of memory and VM

痴心易碎 提交于 2020-02-06 01:34:07
问题 I was reading up on Virtual Memory and from what I understand is that each process has its own VM table that maps VM addresses to Physical Addresses in real memory. So if a process allocated objects continuously they can potentially be stored in completely different places in Physical Memory. My question is that if I allocate and array which is supposed to be stored in a contiguous block of memory and if the size of the array requires more space than one page can provide, from what I

Does requiring a gem load everything, including things I don't use?

一笑奈何 提交于 2020-02-02 11:45:45
问题 Assume x is a gem, that contains both Hello and Goodbye classes. If I write a program that require 'x' , but only uses the Hello class. Is the Goodbye class loaded as well? 回答1: You include scripts or files, not gems. With require 'x' you load the file x.rb . Which x.rb you load is defined by the search path, the search pathes can be modified by gem definitions (what you didn't use in your example code). Everything inside the file x.rb is loaded. If x.rb contains other require commands, those

Does terminating a program reclaim memory in the same way as free()?

那年仲夏 提交于 2020-02-02 03:17:06
问题 I saw this answer to a stack overflow question that says that freeing memory at the very end of a c program is actually harmful because it moves variables that wouldn't be used again into system memory. I'm confused why the free() method in C would do anything different than the operating system reclaiming the heap at the end of the program. Does anyone know if there is a real difference between free() and termination in terms of memory management and if so how the operating system may treat

Linux - Mapping user space memory in kernel code

谁说我不能喝 提交于 2020-02-01 06:29:26
问题 i am writing a piece of code that needs to store 10k of memory located in specific physical address before the SOC shuts down. My problem is that this physical address is not part of kernel space so i have to create an ad -hoc memory mapping so i can access this memory space. i tried using io-remap but it doesn't (apparently) work on non-kernel space. is there any API for doing this ? should i used kmap ? Thanks in advance 回答1: Sounds like memory mapped peripheral. For tight binding into your

Linux - Mapping user space memory in kernel code

安稳与你 提交于 2020-02-01 06:29:16
问题 i am writing a piece of code that needs to store 10k of memory located in specific physical address before the SOC shuts down. My problem is that this physical address is not part of kernel space so i have to create an ad -hoc memory mapping so i can access this memory space. i tried using io-remap but it doesn't (apparently) work on non-kernel space. is there any API for doing this ? should i used kmap ? Thanks in advance 回答1: Sounds like memory mapped peripheral. For tight binding into your

Process sizes and differences in behaviour on 32bit vs. 64bit Windows versions

时光怂恿深爱的人放手 提交于 2020-02-01 05:50:06
问题 I am investigating a strange problem with my application, where the behaviour is different on 2 versions of Windows: Windows XP (32-bit) Windows Server 2008 (64-bit) My findings are as follows. Windows XP (32-bit) When running my test scenario, the XML parser fails at a certain point during the parsing of a very large configuration file (see this question for more information). At the time of failure, the process size is approximately 2.3GB. Note that a registry key has been set to allow the