memory-management

Increasing C++ Program CPU Use

安稳与你 提交于 2021-02-07 07:58:32
问题 I have a program written in C++ that runs a number of for loops per second without using anything that would make it wait for any reason. It consistently uses 2-10% of the CPU. Is there any way to force it to use more of the CPU and do a greater number of calculations without making the program more complex? Additionally, I compile with C::B on a Windows computer. Essentially, I'm asking whether there is a way to make my program faster by increasing usage of CPU, and if so, how. 回答1: Assuming

Does std::initializer_list heap allocate memory?

◇◆丶佛笑我妖孽 提交于 2021-02-07 07:53:42
问题 Simple question, does std::initializer_list heap allocate memory? I'm not talking about its element items, just the buffer itself to store the elements. 回答1: Here's what cppreference has to say (emphasis mine): The underlying array is not guaranteed to exist after the lifetime of the original initializer list object has ended. The storage for std::initializer_list is unspecified (i.e. it could be automatic, temporary, or static read-only memory, depending on the situation). (until C++14) The

Deleting an object when multiple pointers are pointing to it?

一笑奈何 提交于 2021-02-07 06:22:44
问题 I've been told that when if I have multiple pointers pointing to the same object, I cannot delete it normally (using the delete keyword). Instead, I've been told that I need to set the pointers to NULL or 0. Given I have: ClassA* object = new ClassA(); ClassA* pointer1 = object; ClassA* pointer2 = object; So to delete pointer1 and pointer2 , do I need to do the following? pointer1 = 0; pointer2 = 0: Once I've set it to NULL, do I still need to use the keyword delete ? Or is just setting it to

Programmatically counting cache faults

怎甘沉沦 提交于 2021-02-07 06:09:26
问题 I need to evaluate the time taken by a C++ function in a bunch of hypothesis about memory hierarchy efficiency (e.g: time taken when we have a cache miss, a cache hit or page fault when reading a portion of an array), so I'd like to have some libraries that let me count the cache miss / page faults in order to be capable of auto-generating a performance summary. I know there are some tools like cachegrind that gives some related statistics on a given application execution, but I'd like a

Programmatically counting cache faults

我的梦境 提交于 2021-02-07 06:06:03
问题 I need to evaluate the time taken by a C++ function in a bunch of hypothesis about memory hierarchy efficiency (e.g: time taken when we have a cache miss, a cache hit or page fault when reading a portion of an array), so I'd like to have some libraries that let me count the cache miss / page faults in order to be capable of auto-generating a performance summary. I know there are some tools like cachegrind that gives some related statistics on a given application execution, but I'd like a

Go 1.13 RSS keeps on increasing, suspected scavenging issue

元气小坏坏 提交于 2021-02-07 03:41:13
问题 We are experiencing RSS that keeps on increasing in one of our Go service. We are suspecting it's due to scavenger not returning memory to OS properly (or OS not taking back the memory due to use of MADV_FREE). Checked via pprof, no memory leak detected. We tried some experiment with the following simple Go program: Go version: go1.13.4 linux/amd64 (tried with go1.13.1 too) package main import ( "fmt" "time" ) func allocate(s int) { a := make([]byte, s * 1024 * 1024) for i := 0;i < len(a); i

Why does mmap fail on iOS?

烈酒焚心 提交于 2021-02-06 10:12:36
问题 I'm trying to use mmap to read and play audio files on iOS. It works fine for files up to about 400MB. But when I try a 500MB file, I get a ENOMEM error. char *path = [[[NSBundle mainBundle] pathForResource: @"test500MB" ofType: @"wav"] cStringUsingEncoding: [NSString defaultCStringEncoding]]; FILE *f = fopen( path, "rb" ); fseek( f, 0, SEEK_END ); int len = (int)ftell( f ); fseek( f, 0, SEEK_SET ); void *raw = mmap( 0, len, PROT_READ, MAP_SHARED, fileno( f ), 0 ); if ( raw == MAP_FAILED ) {

Why does an empty struct in C# consume memory

吃可爱长大的小学妹 提交于 2021-02-05 20:28:00
问题 I always understood structs (value types) contain exactly the number of bytes as defined in the fields of the structure... however, I did some tests and there seems to be an exception for the empty structs: public class EmptyStructTest { static void Main(string[] args) { FindMemoryLoad<FooStruct>((id) => new FooStruct()); FindMemoryLoad<Bar<FooStruct>>((id) => new Bar<FooStruct>(id)); FindMemoryLoad<Bar<int>>((id) => new Bar<int>(id)); FindMemoryLoad<int>((id) => id); Console.ReadLine(); }

Why does an empty struct in C# consume memory

允我心安 提交于 2021-02-05 20:25:22
问题 I always understood structs (value types) contain exactly the number of bytes as defined in the fields of the structure... however, I did some tests and there seems to be an exception for the empty structs: public class EmptyStructTest { static void Main(string[] args) { FindMemoryLoad<FooStruct>((id) => new FooStruct()); FindMemoryLoad<Bar<FooStruct>>((id) => new Bar<FooStruct>(id)); FindMemoryLoad<Bar<int>>((id) => new Bar<int>(id)); FindMemoryLoad<int>((id) => id); Console.ReadLine(); }

How does PAE (Physical Address Extension) enable an address space larger than 4GB?

删除回忆录丶 提交于 2021-02-05 20:10:40
问题 An excerpt of Wikipedia's article on Physical Address Extension: x86 processor hardware-architecture is augmented with additional address lines used to select the additional memory, so physical address size increases from 32 bits to 36 bits. This, theoretically, increases maximum physical memory size from 4 GB to 64 GB. Along with an image explaining the mechanism: But I can't see how the address space is expanded from 4GB to 64GB. And 4 * 512 * 512 * 4K still equals 4GB, isn't it? 回答1: x86