Questions tagged [allocation]
The allocation tag has no summary.
35 questions
0
votes
2
answers
303
views
What should I consider when determining what `ALLOC_MAX` should be in this type of I/O loop?
For, e.g. determining an amount of memory that is safe to allocate for processing file or device with this type of I/O loop:
HANDLE hFile /* = file open with GENERIC_READ */;
LARGE_INTEGER liSize;
...
16
votes
6
answers
10k
views
Unstable output C++: running the same thing twice gives different output
So, the problem:
When I run the same C++ code in Visual Studio, with the same input and parameters, I get either the correct output, or an output that is completely messed up (99% of values go to zero)...
1
vote
3
answers
379
views
What is the standard for heap allocators in bare metal programs?
What is the standard for heap allocation systems in bare metal programs? If there is no standard, what is the most popular one? Is it a free list? If so, are there heuristics that use a hash table of ...
0
votes
5
answers
296
views
Load and process (compressed) data from filesystem in the blink of an eye
We have a huge amount of queries hitting our API that request a minor or major extract of some huge files lying around on our mounted hard drives. The data needs to be extracted from the files and ...
6
votes
2
answers
2k
views
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 ...
0
votes
1
answer
165
views
How do custom allocators know which addresses of memory they can allocate?
I was looking at Rust's Allocator trait. From my understanding, you give an allocator a length of memory and a word size to align to, and the allocator either gives you a pointer to the memory or an ...
1
vote
4
answers
1k
views
Using output arguments in C++ to avoid dynamic allocations
I have a function that repeatedly encodes Foos to string. I'm currently deciding between two ways to implement this:
Return by value:
std::string encode(const Foo& foo);
void important_function() ...
0
votes
3
answers
265
views
What goes into a computer deciding how many memory locations to assign for specific data types in C?
I have learned file memory management and some very simple CPU assembly for manual memory manipulation. Still, I feel like there is a gap in my knowledge when it comes to modern, complex computers, ...
0
votes
4
answers
760
views
Design pattern for embedding constructor arguments into classes/structs
I am still quite new on here so I hope I am posting in right forum.
I am currently writing a small library where I realized I could use some kind of design pattern which lets one pass constructor ...
2
votes
1
answer
124
views
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 ...
16
votes
2
answers
7k
views
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 <iostream>
#include <memory>
#include <vector>
using namespace std;
class base
{
void virtual initialize_vector() = 0;
};
...
3
votes
7
answers
2k
views
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. ...
26
votes
2
answers
9k
views
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 ...
-2
votes
1
answer
907
views
First Fit Algorithm Memory Allocation
I am currently reviewing memory partitions and I have a problem that is really confusing me. Suppose you have 5 memory partitions: 100K, 500K, 200K, 300K, and 600K.
Also suppose you have 4 ...
1
vote
0
answers
490
views
Constructing a stateful allocator using an interface
I have the following abstract class which implements the "Allocator" concept, using policies and traits to customize behavior:
#define FORWARD_ALLOCATOR_TRAITS(C) \
typedef ...
1
vote
4
answers
2k
views
How does C++ dynamic allocation work?
I have a big doubt about dynamic allocation. Suppose you have a class like this:
class MyClass {
public:
MyClass() {}
~MyClass() {}
private:
std::vector<...
3
votes
3
answers
2k
views
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 ...
3
votes
1
answer
809
views
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<class BaseAllocator,
std::...
5
votes
5
answers
2k
views
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 ...
0
votes
2
answers
139
views
Question answer allocation algorithm
We have a big set of survey questions, which we distribute to users online. We collect submission from users and based on their submission, we decide the answers for those questions. Now, each user ...
3
votes
2
answers
2k
views
How do Virtual Machines allocate memory?
If I want to allocate a struct in C,
#include<stdio.h>
typedef struct container {
int i;
} Container;
int main() {
Container *ptr_to_container;
ptr_to_container = (Container *) ...
2
votes
2
answers
136
views
Most efficient way of allocating participants to conference tracks
I am redesigning a system by which conference participants can choose which track they want to attend. Participants express their track preferences arranging them in order and submitting them at a ...
1
vote
1
answer
228
views
Static memory idiom
I am on a micro controller (which means I can only have static memory allocation) and I am trying to work with inheritance.....
Suppose I have a abstract class Image and an abstract class Font. An ...
1
vote
0
answers
116
views
Resource Allocation Algorithm
I have a question about assigning values to nodes laid out in a physical space:
There is a set of N fixed nodes spread out throughout a certain 2 dimensional region that need to be assigned a value ...
2
votes
1
answer
6k
views
Big O notation allocate array of N element
In Big O notation, allocate an array of N element is defined by O(1) or O(n) ?
For example in C#, if I allocate an array like this :
int[] a = new int[10]
When I display this array, I have :
{0,0,0,...
6
votes
1
answer
428
views
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 ...
9
votes
3
answers
9k
views
Why std::allocators are not that popular? [closed]
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 ...
0
votes
2
answers
5k
views
Dynamic initialization, how does it work?
I have a question regarding dynamic initialization.
Example code
void main()
{
int a = 100;
//Statement1
//Statement2
...
float b = 6.32987; //StatementA
...
return;
}
The StatementA allocates ...
7
votes
2
answers
8k
views
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 ...
1
vote
0
answers
326
views
Development of algorithmical concept for scheduling and allocation problem
I have to solve a problem in the field of operations research. I want to gather some general approaches to evaluate them to pick the most promising to design a problem-related program.
Problem ...
2
votes
2
answers
9k
views
What is a good algorithm for priority allocation of work duties?
I am currently doing a project (in PHP) that has the following requirements:
There is a list of people, sorted in a certain priority. Work should be allocated to them by this priority. e.g. If the ...
3
votes
2
answers
5k
views
How are new[] and malloc implemented in Windows? [closed]
So when you call malloc or new [] from your C/C++ application, how does the CRT translate it into Windows API calls?
1
vote
3
answers
397
views
Allocation problem identification
I have a matrix. I have a list of people who have to occupy n1,n2,n3 etc cells, different number of cells in different rows. I have to place the people in the cells. Occupying the same cell across ...
11
votes
4
answers
5k
views
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 ...
5
votes
2
answers
645
views
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,...