Memory allocation is an operation of giving a program a block of memory.
Questions tagged [allocation]
1869 questions
14
votes
1 answer
Placing Python objects in shared memory
Is there a Python module that would enable me to place instances of non-trivial user classes into shared memory?
By that I mean allocating directly in shared memory as opposed to pickling into and out of it.
multiprocessing.Value and…

NPE
- 486,780
- 108
- 951
- 1,012
14
votes
2 answers
Memory allocations in Julia
I'm extremely dissatisfied after translating a program from Python to Julia:
for small/very small inputs, Python is faster
for medium inputs, Julia is faster (but not that much)
for big inputs, Python is faster
I think the reason is that I don't…

Pigna
- 2,792
- 5
- 29
- 51
14
votes
1 answer
Efficient way to allot the next available VM
The method getNextAvailableVm() allots virtual machines for a particular data center in a round-robin fashion. (The integer returned by this method is the machine allotted)
In a data center there could be virtual machines with different set of…

saplingPro
- 20,769
- 53
- 137
- 195
13
votes
1 answer
Calculate vector whose length is not known beforehand - should I "grow" it?
I need to calculate entries of a vector whose length I do not know beforehand. How to do so efficiently?
A trivial solution is to "grow" it: start with a small or empty vector and successively append new entries until the stopping criterion is…

Stephan Kolassa
- 7,953
- 2
- 28
- 48
13
votes
1 answer
Does std::array of std::array have contiguous memory?
Seems, that I found how to easily get normal 2D Array with contiguous memory in 2 lines of code:
template
using Array2D = array, N>;
Let's solve easy task of swapping min and max in Array2D (a little of…

MrPisarik
- 1,260
- 1
- 11
- 21
13
votes
1 answer
To preallocate or not to preallocate lists in Python
When should and shouldn't I preallocate a list of lists in python?
For example, I have a function that takes 2 lists and creates a lists of lists out of it.
Quite like, but not exactly, matrix multiplication. Should I preallocate the result,
X =…

cheezsteak
- 2,731
- 4
- 26
- 41
12
votes
3 answers
Allocating arrays of the same size
I'd like to allocate an array B to be of the same shape and have the same lower and upper bounds as another array A. For example, I could use
allocate(B(lbound(A,1):ubound(A,1), lbound(A,2):ubound(A,2), lbound(A,3):ubound(A,3)))
But not only is…

user1173081
- 137
- 1
- 5
12
votes
3 answers
how to properly allocate memory in C++ in low memory conditions
I have seen resources show two ways of allocating memory while ensuring that there was enough memory to complete the operation.
1) wrap the 'new' operation in a try/catch since it'll return std::bad_alloc (?)
try { ptr = new unsigned…

jbu
- 15,831
- 29
- 82
- 105
12
votes
3 answers
Memory allocated with alloca gets freed at end of function or at end of scope?
If I have a function like this:
void bla(int size) {
while(b){
char tmp[size];
......
}
}
tmp gets freed at each iteration of the while loop, right?
If I write this function:
void bla(int size) {
while(b){
char*…

Damian
- 5,471
- 11
- 56
- 89
12
votes
4 answers
Why doesn't this C++ STL allocator allocate?
I'm trying to write a custom STL allocator that is derived from std::allocator, but somehow all calls to allocate() go to the base class. I have narrowed it down to this code:
template class a : public std::allocator {
public:
T*…

Dirk Groeneveld
- 2,547
- 2
- 22
- 23
11
votes
4 answers
Editable javascript chart - interactively resize bars or pie sections
I need a library or a framework plugin that can draw charts that can be modified real-time by resizing part of the chart itself. Is there such thing?
I plan to use it for adjusting the chart values. Mostly for controlling amount allocation.
For…

antitoxic
- 3,746
- 1
- 37
- 46
11
votes
1 answer
Return lazy iterator that depends on data allocated within the function
I am new to Rust and reading The Rust Programming Language, and in the Error Handling section there is a "case study" describing a program to read data from a CSV file using the csv and rustc-serialize libraries (using getopts for argument…

Elias Riedel Gårding
- 318
- 1
- 8
11
votes
2 answers
Difference between local allocatable and automatic arrays
I am interested in the difference between alloc_array and automatic_array in the following extract:
subroutine mysub(n)
integer, intent(in) :: n
integer :: automatic_array(n)
integer, allocatable ::…

Nordico
- 1,226
- 2
- 15
- 31
11
votes
2 answers
linux high kernel cpu usage on memory initialization
I have a problem with high CPU cunsumption by the linux kernel, while bootstrapping my java applications on server. This problem occurs only in production, on dev servers everything is light-speed.
upd9: There was two question about this issue:
How…

Dmitry
- 123
- 1
- 6
10
votes
3 answers
Tracking object allocation in python
Is there any method I can override that will allow me to use print statements / pdb / etc. to keep track of every time an instance of my class is allocated? While unpickling some objects I am seeming to get some that never have either __setstate__…

Ian Goodfellow
- 2,584
- 2
- 19
- 20