Memory allocation is an operation of giving a program a block of memory.
Questions tagged [allocation]
1869 questions
10
votes
5 answers
Does STL Vector use 'new' and 'delete' for memory allocation by default?
I am working on a plugin for an application, where the memory should be allocated by the Application and keep track of it. Hence, memory handles should be obtained from the host application in the form of buffers and later on give them back to the…

rwb
- 621
- 1
- 12
- 21
10
votes
2 answers
How do I allocate an array at runtime in Rust?
Once I have allocated the array, how do I manually free it? Is pointer arithmetic possible in unsafe mode?
Like in C++:
double *A=new double[1000];
double *p=A;
int i;
for(i=0; i<1000; i++)
{
*p=(double)i;
p++;
}
delete[] A;
Is there…
user5280366
10
votes
3 answers
What is "allocation context"?
I'm a student and I have to do a research about memory leak detection. In many papers they are talking about allocation context. I don't know what it means. I can't find any definition of allocation context (or translation, I'm from Germany).
As an…

m.w.
- 311
- 3
- 12
10
votes
2 answers
C++ Allocation of incomplete type
I'm tring to create Card and Deck classes but I'm getting an error message that says
Allocation of incomplete type 'Card'
The problem is happening in Deck::Deck() of Deck.cpp
//
//Deck.h
#ifndef JS_DECK_H
#define JS_DECK_H
#include
using…

blitzeus
- 485
- 2
- 10
- 28
10
votes
4 answers
Declare large array on Stack
I am using Dev C++ to write a simulation program. For it, I need to declare a single dimensional array with the data type double. It contains 4200000 elements - like double n[4200000].
The compiler shows no error, but the program exits on…

Aniruddh Jammoria
- 101
- 1
- 1
- 3
10
votes
2 answers
What does the "new " keyword in .net actually do?
I know that the new keyword is calling the class constructor but at which stage do we allocate memory for the class?
In my understanding it should correspond to the GCHandle.Alloc(Object) method but I'm unable to find the connection.

Sergey Kravchenko
- 119
- 6
9
votes
4 answers
Memory pools implementation in C
I am looking for a good memory pool implementation in C.
it should include the following:
Anti fragmentation.
Be super fast :)
Ability to "bundle" several allocations from different sizes under some identifier and delete all the allocations with…

Avi Zrachya
- 151
- 2
- 6
9
votes
3 answers
Why does shrink_to_fit (if the request is fulfilled) cause reallocation?
Given a container v with v.size() == 3 and v.capacity() == 5, my understanding is that a call to v.shrink_to_fit() can be fulfilled and, if it is, it causes v.capacity() to become 3.
However, this comes at the cost of a reallocation.
Why? Isn't it…

Enlico
- 23,259
- 6
- 48
- 102
9
votes
2 answers
std::allocator construct/destroy vs. placement new/p->~T()
For a project of mine, I am writing some STL containers from scratch (I have my reasons). Since I am mimicking the functionality and interfaces of the STL so closely I am doing my best to keep with the policy "if it has the same name as a standard…

Evan Teran
- 87,561
- 32
- 179
- 238
9
votes
1 answer
Passing size as argument VS assuming shape in Fortran procedures
I'm trying to decide which one of these two options would be the best:
subroutine sqtrace( Msize, Matrix, Value )
integer, intent(in) :: Msize
real*8, intent(in) :: Matrix(Msize, Msize)
real*8, intent(out) :: Value
…

Nordico
- 1,226
- 2
- 15
- 31
9
votes
5 answers
Alignment restrictions for malloc()/free()
Older K&R (2nd ed.) and other C-language texts I have read that discuss the implementation of a dynamic memory allocator in the style of malloc() and free() usually also mention, in passing, something about data type alignment restrictions.…
anon c hacker
9
votes
6 answers
Why Vector's size() and capacity() is different after push_back()
I just starting to learning vectors and little confused about size() and capacity()
I know little about both of them. But why in this program both are different? even array(10) is making room for 10 elements and initializing with 0.
Before adding…

Asif Mushtaq
- 3,658
- 4
- 44
- 80
9
votes
1 answer
this device is not currently online
I wanted to use Instruments Version 7.1 (7B91b) to analysis my app. But when I launch the Allocations Instruments, the record button is disabled.I have connected my iPhone device(iPhone 6 plus with iOS version 9.1) and the device can be debugged…

tbago
- 660
- 1
- 6
- 19
9
votes
13 answers
Dynamically allocate C struct?
I want to dynamically allocate a C struct:
typedef struct {
short *offset;
char *values;
} swc;
Both 'offset' and 'values' are supposed to be arrays, but their size is unknown until runtime.
How can I dynamically allocate memory for my…

pf.
- 101
- 1
- 1
- 2
9
votes
1 answer
strange slowing down of C++ allocs
Could someone please tell me why following things could happen:
I have 2 computers:
my working comp
Server
I maintain C++ program (msvc 2005 c++ compiled) that works too slow only on server,
but not on my comp.
I conducted measurements…

Andrew Lebedeff
- 91
- 3