memory-management

Memory efficient way to represent shortest path?

流过昼夜 提交于 2021-01-28 19:08:57
问题 Say I am given the shortest path from node A to node B. The path is simply a list of edges, so a path A->B->C, will be represented as [(A,B),(B,C)]. Currently, each node is of type string , a path from one node to another, say (A, B), is a set of string, and the path is a list of sets. Now, the path consists of over 60k edges, and it must be saved to a database for later retrieval. So obviously, I need a very nice way to represent this path in C++ such that: the size of the path is

ARM64 - Linux Memory Write protection won't disable

喜你入骨 提交于 2021-01-28 09:51:53
问题 i'm trying to disable the Memory Write protection on an ARM64 system from within an LKM. (Startet in the DOM0 of the Xen hypervisor) I found the corresponding PTE to an virtual address by using the Linux Kernel Functions. pgd_t *pgd; pte_t *ptep, pte; pud_t *pud; pmd_t *pmd; pgd = pgd_offset(init_mm, (addr)); if (pgd_none(*pgd) || pgd_bad(*pgd)) goto out; printk(KERN_NOTICE "Valid pgd 0x%lx\n",pgd); pud = pud_offset(pgd, addr); if (pud_none(*pud) || pud_bad(*pud)) goto out; printk(KERN_NOTICE

Does NSValue free its value when freed?

╄→尐↘猪︶ㄣ 提交于 2021-01-28 06:33:15
问题 Have a look at this pseudocode: void* magicpointer = malloc(OVER_NINE_THOUSAND); NSValue* v = [NSValue valueWithPointer:magicpointer]; [v release]; When v is released, does magicpointer get freed as well, or do I have to do that manually? I am using manual reference counting. 回答1: It doesn't get freed - NSValue is just a wrapper so you can treat arbitrary values as objects. It doesn't do anything with the wrapped pointer. 回答2: No, NSValue won't. Sounds like you might want to use NSData , it

How is an array of object[]s stored in memory?

浪尽此生 提交于 2021-01-28 06:08:49
问题 As I understand it, the elements of an array are stored contiguously in memory, and accessing a particular one it is done by adding the product of the desired index and the size of each element with the base array address to find the address of the element. Since in a language like C# I can create an array of object[] s and put whatever data type I want in it, how is each element of the array stored (and kept) at a uniform length if I used differently sized types while still allowing for

Can we use non-temporal mov instructions on heap memory?

天涯浪子 提交于 2021-01-28 05:08:27
问题 In Agner Fog's "Optimizing subroutines in assembly language - section 11.8 Cache control instructions," he says: "Memory writes are more expensive than reads when cache misses occur in a write-back cache. A whole cache line has to be read from memory, modified, and written back in case of a cache miss. This can be avoided by using the non-temporal write instructions MOVNTI, MOVNTQ, MOVNTDQ, MOVNTPD, MOVNTPS . These instructions should be used when writing to a memory location that is unlikely

c++ double free or corruption (out) error

≯℡__Kan透↙ 提交于 2021-01-28 03:22:40
问题 I am getting error of "Double free or corruption(out)" after I print my output. But this error is only coming for small inputs. For bigger inputs program doesn't throw that error. When I create the multidimensional arrays inside the main and delete them, I do not get the error. I have only posted the part of the code which is relevant to this issue here. Please kindly explain how to resolve the issue. #include<iostream> #include<vector> using namespace std; class Knapsack{ public: int noItems

What is the difference between memory leak, accessing freed memory and double free?

落花浮王杯 提交于 2021-01-28 00:13:09
问题 I'm trying to figure out what is the difference between those three kinds of problems associated with memory models. If I want to simulate a memory leak scenario, I can create a pointer without calling corresponding delete method. int main() { // OK int * p = new int; delete p; // Memory leak int * q = new int; // no delete } If I want to simulate a double free scenario, I can free a pointer twice and this part memory will be assigned twice later. a = malloc(10); // 0xa04010 b = malloc(10); /

Is there a way to open hdf5 files with the POSIX_FADV_DONTNEED flag?

隐身守侯 提交于 2021-01-27 20:35:50
问题 We are working with large (1.2TB) uncompressed, unchunked hdf5 files with h5py in python for a machine learning application, which requires us to work through the full dataset repeatedly, loading slices of ~15MB individually in a randomized order. We are working on a linux (Ubuntu 18.04) machine with 192 GB RAM. We noticed that the program is slowly filling the cache. When total size of cache reaches size comparable with full machine RAM (free memory in top almost 0 but plenty ‘available’

How to use Minimal GC in VC++ 2013? [duplicate]

拟墨画扇 提交于 2021-01-27 19:52:18
问题 This question already has an answer here : Garbage Collection in C++11 (1 answer) Closed 7 years ago . According to here, VC++ 2013 supports Minimal GC. Could you guys give me some examples to illustrate its usage? In other words, with VC++ 2013, how to use GC? The code example I want might look like this: auto p = gcnew int; Are there any? 回答1: You may be disappointed about what Minimal GC in C++11: It doesn't do garbage collection! The minimal garbage collection support in C++11 consists of

How garbage collection decides generation for variable

↘锁芯ラ 提交于 2021-01-27 18:05:36
问题 I know GC has 3 (0, 1, 2) generations but I'm wondering how GC decides the generation for a variable? I thought all variables go into generation 0 and after some time move to generations 1 and 2. Is it size matter for GC to decide the generation? Program1: private static void Main(string[] args) { int a = 0; string name = "Test"; var byteArray = new byte[10]; byteArray[4] = 4; Console.WriteLine($"Generation of array {GC.GetGeneration(byteArray)}"); Console.WriteLine($"Generation of local int