When the VC6 C runtime on XP can't serve an allocation request within an existing heap segment, it reserves a new segment. The size of these new segments increase by factors of 2 (until there are not large enough free areas to do that, at which point it falls down to smaller segments.)
In any case, is there any way to control this behav...
I am porting an application to an ARM platform in C, the application also runs on an x86 processor, and must be backward compatible.
I am now having some issues with variable alignment. I have read the gcc manual for
__attribute__((aligned(4),packed)) I interpret what is being said as the start of the struct is aligned to the 4 byte bo...
So I am trying to create a Memory Management System. In order to do this I have a set amount of space (allocated by malloc) and then I have a function myMalloc which will essentially return a pointer to the space allocated. Since we will then try and free it, we are trying to set a header of the allocated space to be the size of the al...
Please kindly advise on benchmarks used to test a C and C++ allocator? Benchmarks satisfying any of the following aspects are considered:
Speed
Fragmentation
Concurrency
Thanks!
...
I am using Delphi 2009 which has the FastMM4 memory manager built into it.
My program reads in and processes a large dataset. All memory is freed correctly whenever I clear the dataset or exit the program. It has no memory leaks at all.
Using the CurrentMemoryUsage routine given in spenwarr's answer to: http://stackoverflow.com/questi...
Why new()/delete() is slower than malloc()/free()?
EDIT:
Thanks for the answers so far. Please kindly point out specifications of standard C++ implementation of new() and delete() if you have them thanks!
...
int main()
{
int p;
scanf("%d",&p);
fun()
{
int arr[p]; //isn't this similar to dynamic memory allocation??
}
}
//if not then what other objective is achieved using malloc and calloc??
//Someone please throw some light :-)
...
Here is two variants. First:
int n = 42;
int* some_function(int* input)
{
int* result = new int[n];
// some code
return result;
}
int main()
{
int* input = new int[n];
int* output = some_function(input);
delete[] input;
delete[] output;
return 0;
}
Here the function returns the memory, allocated insi...
What exactly happens, in terms of memory, when i declare something like:
char arr[4];
How many bytes are reserved for arr?
How is null string accommodated when I 'strcpy' a string of length 4 in arr?
I was writing a socket program, and when I tried to suffix NULL at arr[4] (i.e. the 5th memory location), I ended up replacing the value...
I want to extensively test some pieces of C code for memory leaks.
On my machine I have 4 Gb of RAM, so it's very unlikely for a dynamic memory allocation to fail. Still I want to see the comportment of the code if memory allocation fails, and see if the recover mechanism is "strong" enough.
What do you suggest ? How do I emulate an en...
I am just starting out C++, so sorry if this is a dumb question. I have a class Braid whose members are vectors. I have not written an assignment operator. When I do a lot of assignments to an object of the type Braid, I run into memory issues :-
0 0xb7daff89 in _int_malloc () from /lib/libc.so.6
#1 0xb7db2583 in malloc () from /lib/...
Take the following code
class A {
};
class B : public A {
};
class C : public A {
int x;
};
int main (int argc, char** argv) {
A* b = new B();
A* c = new C();
//in both cases, only ~A() is called, not ~B() or ~C()
delete b; //is this ok?
delete c; //does this line leak memory?
return 0;
}
when calling delete on...
So,
I have some code which looks like this:
byte* ar;
foo(ar) // Allocates a new[] byte array for ar
...
delete[] ar;
To make this safer, I used a scoped_array:
byte* arRaw;
scoped_array<byte> ar;
foo(arRaw);
ar.reset(arRaw);
...
// No delete[]
The question is, Is there any existing way to do this using just the scoped_array, with...
Hello,
I try to understand the memory management in ObjectiveC and still some things are a misery for me.
I've got an instance variable:
NSMutableArray *postResultsArray;
when a button is clicked in the UI I create new array:
self.postResultsArray = [NSMutableArray array];
then I add some objects to the array and when the who...
Is there a way to access (read or free) memory chunks that are outside the memory that is allocated for the program without getting access violation exceptions.
Well what I actually would like to understand apart from this, is how a memory cleaner (system garbage collector) works. I've always wanted to write such a program. (The languag...
Why is the following code resulting in Segmentation fault? (I'm trying to create two matrices of the same size, one with static and the other with dynamic allocation)
#include <stdio.h>
#include <stdlib.h>
//Segmentation fault!
int main(){
#define X 5000
#define Y 6000
int i;
int a[X][Y];
int** b = (int**) malloc(...
What is the impact of creating variables using:
Dim ds as New DataSet
ds = GetActualData()
where GetActualData() also creates a New DataSet and returns it?
Does the original empty DataSet that was 'New'ed just get left in the Heap?
What if this kind of code was in many places? Would that affect the ASP.NET process and cause...
I need help with debugging this piece of code. I know the problem is in malloc and free but can't find exactly where, why and how to fix it. Please don't answer: "Use gdb" and that's it. I would use gdb to debug it, but I still don't know much about it and am still learning it, and would like to have, in the meanwhile, another solution.
...
In order to find more easily buffer overflows I am changing our custom memory allocator so that it allocates a full 4KB page instead of only the wanted number of bytes. Then I change the page protection and size so that if the caller writes before or after its allocated piece of memory, the application immediately crashes.
Problem is t...
I have a function which takes a variable number of pointers, which I would like to modify. It looks something like:
void myPointerModifyingFunction (int num_args, ... ) {
void *gpu_pointer;
char mem_type;
va_list vl;
va_start(vl,num_args);
for (int i=0;i<num_args;i++) {
gpu_pointer=va_arg(vl,void*);
...