memory-management

When is finalize() invoked during garbage collection?

泄露秘密 提交于 2021-02-16 14:59:41
问题 From : Q11 of https://www.baeldung.com/java-memory-management-interview-questions When an object becomes eligible for GC, the garbage collector has to run the finalize() on it; this method is guaranteed to run only once, thus the collector flags the object as finalized and gives it a rest until the next cycle. I have a few questions to ask: Is that statement correct? Is it during the marking phase, does the garbage collector invoke the finalize() method? Why does it give a rest until the next

Why use dynamic memory allocation(i.e. malloc()) when implementing linked list in c?

跟風遠走 提交于 2021-02-15 05:34:57
问题 Okay this question may sound stupid to the amateur programmers . But seriously this is bothering me and a solemn answer to this doubt of mine is welcomed. I have just started to take my first ever course in data structures. And what is bothering me is this: Assuming C is used, //Implementing a node struct Node { int data; struct *Node; }; Now while creating a node why do we use the dynamic memory allocation technique where we use malloc(). Can't we just create a variable of type ' Struct Node

Why use dynamic memory allocation(i.e. malloc()) when implementing linked list in c?

我只是一个虾纸丫 提交于 2021-02-15 05:34:57
问题 Okay this question may sound stupid to the amateur programmers . But seriously this is bothering me and a solemn answer to this doubt of mine is welcomed. I have just started to take my first ever course in data structures. And what is bothering me is this: Assuming C is used, //Implementing a node struct Node { int data; struct *Node; }; Now while creating a node why do we use the dynamic memory allocation technique where we use malloc(). Can't we just create a variable of type ' Struct Node

Should I call `vkMapMemory` each time I write to a buffer?

自作多情 提交于 2021-02-11 13:36:12
问题 Are there any benefits to using a single vkMapMemory , a memset s for each write, and a single vkUnmapMemory as opposed to using a vkMapMemory , memset , and vkUnmapMemory for each write to a buffer? 回答1: Yes, it is beneficial to map only once. vkMapMemory likely needs to do some system calls, so it is not free. Authoritative quote, e.g. https://developer.samsung.com/game/usage#buffermanagement: Frequent Map/Unmap calls should be avoided. 来源: https://stackoverflow.com/questions/59118275

Using placement new in a container

旧街凉风 提交于 2021-02-11 05:03:38
问题 I just came across some container implementation in C++. That class uses an internal buffer to manage its objects. This is a simplified version without safety checks : template <typename E> class Container { public: Container() : buffer(new E[100]), size(0) {} ~Container() { delete [] buffer; } void Add() { buffer[size] = E(); size++; } void Remove() { size--; buffer[size].~E(); } private: E* buffer; int size; }; AFAIK this will construct/destruct E objects redundantly in Container() and

C++ Program immediately using 2 GB of RAM: how to find culprit?

女生的网名这么多〃 提交于 2021-02-10 17:52:24
问题 I have a program that, when queried on initialisation, is immediately using > 2 GB of RAM. Basically the code is like this: #include <blah> int main() { cout << get_mem_usage() << endl; //Lots of things happen, but no significant memory usage return 0; } Output: [2013-02-15 18:38:05.865283] 2147.71 Mb I am, however, linking to a lot of different shared object files: I checked ldd and I am linking to 58 libraries, with a combined .so size of 66 MB. I'm pretty sure that the get_mem_usage

C++ Program immediately using 2 GB of RAM: how to find culprit?

冷暖自知 提交于 2021-02-10 17:51:37
问题 I have a program that, when queried on initialisation, is immediately using > 2 GB of RAM. Basically the code is like this: #include <blah> int main() { cout << get_mem_usage() << endl; //Lots of things happen, but no significant memory usage return 0; } Output: [2013-02-15 18:38:05.865283] 2147.71 Mb I am, however, linking to a lot of different shared object files: I checked ldd and I am linking to 58 libraries, with a combined .so size of 66 MB. I'm pretty sure that the get_mem_usage

when does an operating system wipes out memory of a process

Deadly 提交于 2021-02-10 15:57:51
问题 A process is terminated successfully or abnormally on some OS, when does an OS decide to wipe out the memory (data, code etc.) allocated to that process; at exit or when it wants to allocate memory to a new process? And is this wiping out memory allocation procedure the same on all operating systems (winXP, Win7, linux, Mac)? I understand, page table has mapping of virtual addresses for that process and actual physical addresses in the memory. Thanks. 回答1: How an OS reclaims process resources

when does an operating system wipes out memory of a process

时光怂恿深爱的人放手 提交于 2021-02-10 15:56:44
问题 A process is terminated successfully or abnormally on some OS, when does an OS decide to wipe out the memory (data, code etc.) allocated to that process; at exit or when it wants to allocate memory to a new process? And is this wiping out memory allocation procedure the same on all operating systems (winXP, Win7, linux, Mac)? I understand, page table has mapping of virtual addresses for that process and actual physical addresses in the memory. Thanks. 回答1: How an OS reclaims process resources

when does an operating system wipes out memory of a process

若如初见. 提交于 2021-02-10 15:56:41
问题 A process is terminated successfully or abnormally on some OS, when does an OS decide to wipe out the memory (data, code etc.) allocated to that process; at exit or when it wants to allocate memory to a new process? And is this wiping out memory allocation procedure the same on all operating systems (winXP, Win7, linux, Mac)? I understand, page table has mapping of virtual addresses for that process and actual physical addresses in the memory. Thanks. 回答1: How an OS reclaims process resources