memory-management

Is there way to verify my program has no memory leaks?

↘锁芯ラ 提交于 2020-08-04 06:50:28
问题 I wish to determine if the following program (an implementation of finding the maximum sub-array) leaks memory. Is there a general way to determine this? Such as using some feature of a debugger? What are general strategies? struct Interval { int max_left; int max_right; int sum; }; struct Interval * max_crossing_subarray(int A[], int low, int mid, int high) { struct Interval * crossing = malloc(sizeof(struct Interval)); int left_sum = INT_MIN; int sum = 0; for(int i = mid; i >= low; --i) {

How does Rust guarantee memory safety and prevent segfaults?

我怕爱的太早我们不能终老 提交于 2020-08-01 06:11:42
问题 I was looking for a language to learn, and I saw that Rust is getting quite popular. Two things impressed me about Rust, memory safety and preventing segfaults. How does Rust achieve this? What differences between Rust and Java for example enable Rust's safety features? 回答1: How Rust achieves memory safety is, at its core, actually quite simple. It hinges mainly on two principles: ownership and borrowing. Ownership The compiler uses an affine type system to track the ownership of each value:

Static class memory allocation where it is stored C#

这一生的挚爱 提交于 2020-07-31 09:04:06
问题 I read an article which confused me about memory allocation, which stated: Singleton objects are stored on the heap while static classes are stored on the stack. link is : http://www.dotnetjalps.com/2013/06/Static-vs-Singleton-in-Csharp-Difference-between-Singleton-and-Static.html But in some Stackoverflow questions, such as How is memory allocated for a static variable? It was described like Static variables are stored on the heap, regardless of whether they are declared as a reference type

is Malloc allocating more memory then needed?

牧云@^-^@ 提交于 2020-07-22 21:34:06
问题 This is an C assignment for school but I'm running into to something strange that I don't know if it is normal or not. I have to take command line arguments and an example of one is -ia.b so within my program I dynamically allocate memory with malloc char *fileName = NULL; fileName = malloc(strlen(argv[i]) * sizeof(char)); //error testing etc strcpy(fileName, argv[i]); Works fine, but I look into memory via visual studio debugger this is what become allocated at the memory location which to

is Malloc allocating more memory then needed?

℡╲_俬逩灬. 提交于 2020-07-22 21:33:22
问题 This is an C assignment for school but I'm running into to something strange that I don't know if it is normal or not. I have to take command line arguments and an example of one is -ia.b so within my program I dynamically allocate memory with malloc char *fileName = NULL; fileName = malloc(strlen(argv[i]) * sizeof(char)); //error testing etc strcpy(fileName, argv[i]); Works fine, but I look into memory via visual studio debugger this is what become allocated at the memory location which to

Performance: memset

家住魔仙堡 提交于 2020-07-14 07:20:50
问题 I have simple C code that does this (pseudo code): #define N 100000000 int *DataSrc = (int *) malloc(N); int *DataDest = (int *) malloc(N); memset(DataSrc, 0, N); for (int i = 0 ; i < 4 ; i++) { StartTimer(); memcpy(DataDest, DataSrc, N); StopTimer(); } printf("%d\n", DataDest[RandomInteger]); My PC: Intel Core i7-3930, with 4x4GB DDR3 1600 memory running RedHat 6.1 64-bit. The first memcpy() occurs at 1.9 GB/sec, while the next three occur at 6.2 GB/s. The buffer size ( N ) is too big for

What is “bit padding” or “padding bits” exactly?

≯℡__Kan透↙ 提交于 2020-07-14 07:12:48
问题 I do not want to molest you with this, but i just can not find anywhere in the internet a well-described explanation for what "bit padding" really is, as well as not in any answer for bit padding-related threads here on StackOverflow. I also searched ISO 9899-1990 for it, in which "bit padding" is refered to but quite not explained as i need it. The only content in the web i found about this was here, where only one ridiculously short explanation of one sentence was given, saying: bit padding

What is “bit padding” or “padding bits” exactly?

放肆的年华 提交于 2020-07-14 07:12:14
问题 I do not want to molest you with this, but i just can not find anywhere in the internet a well-described explanation for what "bit padding" really is, as well as not in any answer for bit padding-related threads here on StackOverflow. I also searched ISO 9899-1990 for it, in which "bit padding" is refered to but quite not explained as i need it. The only content in the web i found about this was here, where only one ridiculously short explanation of one sentence was given, saying: bit padding

x86 Segmented Memory

£可爱£侵袭症+ 提交于 2020-07-10 05:44:50
问题 While reading The Art of Assembly the other day, I came to the section here on memory layout. It started discussing segmented memory, and I didn't think it made a lot of sense. Splitting memory into segments makes perfect sense as a way for organization, but using the function segment + offset , what do you do when the function repeats its outputs? e.g. 1038 + 57 , 57 + 1038 , and 1095 + 0 all come out to the linear address 1095. Isn't that a bad thing? Wouldn't you accidentally address the

x86 Segmented Memory

风流意气都作罢 提交于 2020-07-10 05:42:38
问题 While reading The Art of Assembly the other day, I came to the section here on memory layout. It started discussing segmented memory, and I didn't think it made a lot of sense. Splitting memory into segments makes perfect sense as a way for organization, but using the function segment + offset , what do you do when the function repeats its outputs? e.g. 1038 + 57 , 57 + 1038 , and 1095 + 0 all come out to the linear address 1095. Isn't that a bad thing? Wouldn't you accidentally address the