memory-management

program life in terms of paged segmentation memory

被刻印的时光 ゝ 提交于 2020-04-10 04:31:44
问题 I have a confusing notion about the process of segmentation & paging in x86 linux machines. Will be glad if some clarify all the steps involved from the start to the end. x86 uses paged segmentation memory technique for memory management. Can any one please explain what happens from the moment an executable .elf format file is loaded from hard disk in to main memory to the time it dies. when compiled the executable has different sections in it (text, data, stack, heap, bss). how will this be

Erase elements from a vector of pointers and deallocate the dynamic memory previously allocated via new operator?

北战南征 提交于 2020-03-23 12:16:31
问题 I want to show you this very simple example, the purpose is to sort some strings allocated dynamically and clean the duplicates resizing the vector and deallocating useless occupated memory. #include <iostream> #include <vector> #include <string> #include <algorithm> using namespace std; void print_v (vector<string *>& v) { cout << "----" << endl; for (string*& str : v) cout << *str << " "; cout << endl << "----" << endl; } typedef string * string_ptr; int main() { vector<string_ptr> v; v

Erase elements from a vector of pointers and deallocate the dynamic memory previously allocated via new operator?

筅森魡賤 提交于 2020-03-23 12:16:02
问题 I want to show you this very simple example, the purpose is to sort some strings allocated dynamically and clean the duplicates resizing the vector and deallocating useless occupated memory. #include <iostream> #include <vector> #include <string> #include <algorithm> using namespace std; void print_v (vector<string *>& v) { cout << "----" << endl; for (string*& str : v) cout << *str << " "; cout << endl << "----" << endl; } typedef string * string_ptr; int main() { vector<string_ptr> v; v

Swift: How to know if an instance needs to be copied?

試著忘記壹切 提交于 2020-03-23 09:03:12
问题 In each of the examples below, does blob.0 or text need to be copied? How do you know? Setup import SQLite3 private let static_destructor = unsafeBitCast(0, to: sqlite3_destructor_type.self) private let transient_destructor = unsafeBitCast(-1, to: sqlite3_destructor_type.self) Examples bind_blob func bind_blob(_ stmt: OpaquePointer, _ blob: (UnsafeRawPointer, Int32)) { sqlite3_bind_blob(stmt, 1, blob.0, blob.1, transient_destructor) } bind_blobs func bind_blobs(_ stmt: OpaquePointer, _ blobs:

C++ memory allocation: 'new' throws bad_alloc?

这一生的挚爱 提交于 2020-03-22 10:27:17
问题 In my application I save voxel-data (compressed byte array) and trying to load it back again into memory. But my application crashes in Windows 7 machine (64 bit ,12 GB) giving bad_alloc . This works fine on Linux ,and even runs on some other Windows 7 machine with 4 GB memory. Compressed bye size is about 200Mb and uncompressed byte size is about 300Mb.(so only 500 MB reserved before this 'new' statement,which leaves almost 8 GB excluding system memory ). I don't run any other major memory

C++ memory allocation: 'new' throws bad_alloc?

喜你入骨 提交于 2020-03-22 10:27:14
问题 In my application I save voxel-data (compressed byte array) and trying to load it back again into memory. But my application crashes in Windows 7 machine (64 bit ,12 GB) giving bad_alloc . This works fine on Linux ,and even runs on some other Windows 7 machine with 4 GB memory. Compressed bye size is about 200Mb and uncompressed byte size is about 300Mb.(so only 500 MB reserved before this 'new' statement,which leaves almost 8 GB excluding system memory ). I don't run any other major memory

C++ new int[0] — will it allocate memory?

。_饼干妹妹 提交于 2020-03-18 08:53:59
问题 A simple test app: cout << new int[0] << endl; outputs: 0x876c0b8 So it looks like it works. What does the standard say about this? Is it always legal to "allocate" empty block of memory? 回答1: From 5.3.4/7 When the value of the expression in a direct-new-declarator is zero, the allocation function is called to allocate an array with no elements. From 3.7.3.1/2 The effect of dereferencing a pointer returned as a request for zero size is undefined. Also Even if the size of the space requested

Memory usage for a specific list of object

二次信任 提交于 2020-03-13 06:40:00
问题 i have a list of simples pojos (a User class) with about 15 simple fields & 1 arrayList. Those represent users & maybe 100 or 1000 of them will be store in memory in order to avoid to retrieve them from external system every time. (i'm using Ehcache) I would like to know with a junit test how much memory is used by a list of K of those users. I have the intuition that simple pojo like those one even for a 1000 ones are not threatening in any way (in other words less than 100 Ko) Thanks in

What does pss mean in /proc/pid/smaps

Deadly 提交于 2020-03-12 08:03:29
问题 I was confused about the pss column in /proc/pid/smaps, so I wrote a program to test it: void sa(); int main(int argc,char *argv[]) { int fd; sa(); sleep(1000); } void sa() { char *pi=new char[1024*1024*10]; for(int i=0;i<4;++i) { for(int j=0;j<1024*1024;++j){ *pi='o'; pi++; } } int cnt; for(int i=0;i<6;++i) { for(int j=0;j<1024*1024;++j){ cnt+=*pi; pi++; } } printf("%d",cnt); } $cat /proc/`pidof testprogram`/smaps 08838000-0885b000 rw-p 00000000 00:00 0 [heap] Size: 140 kB Rss: 12 kB Pss: 12

Out of Memory with RAY Python Framework

橙三吉。 提交于 2020-03-05 00:32:49
问题 I have created a simple remote function with ray that utilizes very little memory. However, after running for a short period of time the memory increases steadily and I get a RayOutOfMemoryError Exception. The following code is a VERY simple example of this problem. The "result_transformed" numpy array is being sent to the workers where each worker can do work on this. My simplified calc_similarity function does nothing, but it still runs out of memory. I have added much longer sleep times to