Questions tagged [allocation]
32 questions
25
votes
2 answers
Why can FAT16 not store more than 2 GB?
All the sites I go to look for informations on FAT16 just declaratively state that it can not allocate more than 2 GB. OK. Great. I believe you. But how do you come to that conclusion (other than just testing it)?
Is there some sort of formula one…

SangoProductions
- 361
- 3
- 6
14
votes
2 answers
Why does the base class need to have a virtual destructor here if the derived class allocates no raw dynamic memory?
The following code causes a memory leak:
#include
#include
#include
using namespace std;
class base
{
void virtual initialize_vector() = 0;
};
class derived : public base
{
private:
vector vec;
public:
…

Inertial Ignorance
- 545
- 6
- 14
9
votes
3 answers
Why std::allocators are not that popular?
With the latest trends about C and C++ applications, and with latest I mean the latest years, I was expecting to see std::allocators to be used way more frequently than what it really is.
Modern applications are usually multithreaded or with form of…

user2485710
- 231
- 2
- 7
9
votes
3 answers
In c/c++, are block-scope variables stacked only if the block is executed?
Suppose this:
void func()
{
...
if( blah )
{
int x;
}
...
}
Is the space for x reserved on the stack immediately when func is entered, or only if the block is actually executed?
Or is it the compiler's choice?
Do C and C++ behave the…

Petruza
- 1,008
- 1
- 8
- 14
7
votes
2 answers
What is the best solution for static memory allocation?
I'm working on image processing and I need to use big Images in a critical system.
A good practice for critical systems is to avoid dynamic allocation of memory but what is the design/recommendations for static memory allocation?
If we do a static…

jblasius
- 71
- 1
- 3
6
votes
2 answers
Why would you use 'new' and 'delete' for something that will be referenced through a vector?
I'm going through some code from this article about ECS-systems in game programming and trying to understand it, and something I'm seeing a lot is using heap memory in places where it seems like there is no benefit in doing so. Take this as an…

JensB
- 237
- 1
- 6
6
votes
1 answer
Does assigning NULL in a GC'ed Environment have similar effects to using free()?
I was just writing a function (in C# in this case) that stored huge amounts of data in a local variable early on in the code, let's say at 5% of the functions code.
After that point, the data in this memeory are no longer used,
also the following…

Mark
- 373
- 5
- 13
5
votes
2 answers
Heaps: Why is there a tradeoff between amount of space occupied (fragmentation), and speed at which operations are carried out?
Apparently, the two major judging criteria of the effectiveness of heaps are (1) how much we can minimize the amount of space it takes up and (2) how fast operations on the heap can be carried out, eg, malloc and free
But I was wondering how these…

Dark Templar
- 6,223
- 16
- 46
- 46
4
votes
4 answers
Storing objects whose size are run-time dependent contiguously in memory
The background
I am working on an ECS in C++ for fun and I am trying to make it as efficient as possible. One of the optimisations I am striving to implement is to minimise cache misses by storing the components contiguously in the memory.
Since I…

sjaustirni
- 192
- 3
- 10
3
votes
7 answers
Is there a best practice for allocation/deallocating multiple, dynamic arrays in C?
I was wondering what would be the best approach to allocate/deallocate multiple one-dimensional, dynamic arrays in C. This seems easy at first, however, for me it turned out to be problematic. Consider the following example program, which…

MaxPowers
- 141
- 4
3
votes
3 answers
Is O(log n) for memory management considered slow?
I am talking about single thread general purpose memory allocation/deallocation from a global 'heap' as e.g. every C programmer knows in the form of malloc()/free().
I can't recite the actual title of a paper about a…

Vroomfondel
- 367
- 2
- 10
3
votes
1 answer
How can I efficiently implement batch allocation in a freelist?
I've been implementing Andrei Alexandrescu's allocators as an exercise, but I've gotten stuck on his Freelist. Andrei's Freelist looks something like this:
template

Justin
- 176
- 9
3
votes
2 answers
How are new[] and malloc implemented in Windows?
So when you call malloc or new [] from your C/C++ application, how does the CRT translate it into Windows API calls?

CS01
- 149
- 1
- 4
2
votes
1 answer
Quantity allocation algorithm performance
I have a scenario for which I'll take an analogous example to help understand better.
There are N buckets of known varying capacities.
We have M balls that we need to put in these buckets to fill them fully or partially. The existing algorithm works…

Varinder Singh
- 129
- 2
2
votes
2 answers
How do Virtual Machines allocate memory?
If I want to allocate a struct in C,
#include
typedef struct container {
int i;
} Container;
int main() {
Container *ptr_to_container;
ptr_to_container = (Container *) malloc(sizeof(Container));
ptr_to_container->i =…

jado
- 131
- 5