Questions tagged [pre-allocation]

Pre-allocation (or preallocation) refers to the allocation of resources that are not immediately necessary.

Pre-allocation (or preallocation) is the allocation of resources before they are strictly required, with the expectation that they will be necessary in the near future. The purpose is usually efficiency.

The term is used a lot in the MATLAB community, but occurs in many other contexts as well. In MATLAB, preallocation refers to the allocation of an array before a loop that will fill the array, as opposed to growing the array repeatedly within the loop.

42 questions
0
votes
1 answer

Preallocation of nested structure array

I am trying to pre-allocate a uniformly nested structure array. I'm currently using for loops to allocate values to the array, but I understand that this is slow if the array has not been pre-allocated. The structure I am trying to achieve is…
Jason Tracey
  • 106
  • 8
0
votes
1 answer

MATLAB - S&P daily return matrix: Substitution of the zero matrix inside the for - loop

Good evening, I have to create a daily return matrix based on 174 daily prices of the S&P index. The table from which I fetch such prices is called "prices", and the objective matrix I have to plug the values in is called "stockreturns". I have…
Khasper
  • 3
  • 2
0
votes
1 answer

Preallocation in MATLAB

Problem I have a matrix M which is the following: M = [1, 1, 0, 1, 0, 0, 0; 0, 1, 1, 0, 1, 0, 0; 0, 0, 1, 1, 0, 1, 0; 0, 0, 0, 1, 1, 0, 1; 1, 0, 0, 0, 1, 1, 0; 0, 1, 0, 0, 0, 1, 1; 1, 0, 1,…
Anthony
  • 83
  • 1
  • 7
0
votes
1 answer

Is it possible to preallocate an array using gpuArray, and have write permission to it in a mexcuda setup?

I have written a piece of code in MatLab (2018a) that is a hybrid between standard matlab code and CUDA code, which I have linked using compilation with mexcuda. The core loop in my code contains an interpolation of a matrix, say from size [n x m]…
Floris
  • 508
  • 2
  • 9
0
votes
1 answer

Preallocate memory for object array

I have a self defined class ClassA, and I want to create an empty object array of size N to store N ClassA objects. Right now I am using an empty cell array cellarrayA = cell(N,1), and putting each object into the cell, like cellarrayA(n) =…
LWZ
  • 11,670
  • 22
  • 61
  • 79
0
votes
1 answer

MATLAB: Growing hash table

I use a hash table in my code and when the code is running I add keys and values into the hash table. At first, I thought using a hash table make my code faster but I was wrong and using hash table has made it slower. As I searched about it, I…
user4704857
  • 469
  • 4
  • 18
0
votes
1 answer

Preallocating a Matrix of .NET Arrays

I'm using Matlab to setup the data acquisition process for an experiment, the function ain.DAQbufferGet is what reads the data from our hardware. It holds a series of data points such as [-200,-160,10,50,-20,40,170,160,-200... etc]. The problem is…
JCW
  • 43
  • 7
0
votes
1 answer

Why does matlab warn to preallocate a variable which is getting reset every loop?

There is a cell variable in my program which Matlab warns to preallocate it. The simple form of code is sth like this: for i = 1:2 a = []; a = [a,{'abc'}]; end First I want to know why a should be preallocated, since it's getting reset in…
M Mahdi
  • 33
  • 1
  • 7
0
votes
1 answer

How to do preallocation in storing field variables in matlab

I am storing the field variables calculated in a for loop in a vector by appending the values, However I would like to preallocate first for performance. I tried to vectorize this operation but it does not give me what I would like to accomplish. I…
Johnny
  • 43
  • 6
0
votes
2 answers

Initialize 64 by 64 numpy of (0,0) tuples in python?

Is it possible to create a numpy of any arbitrary data structure, for example tuples? If yes, how do I initialize it without writing it out? (Obviously, I don't want to write out 64 by 64 array)
Alex Azazel
  • 332
  • 5
  • 18
0
votes
0 answers

Disable prealloc in ext4

I need to disable prealloc feature in ext4. But there is not a mount feature called disprealloc. I would like to know if there are any methods to disable prealloc feature. Any suggestions in this regard will be appreciated
wenyi liu
  • 71
  • 6
-1
votes
1 answer

Variable size element in embedded function but fixed input and output

I have a fixed input and output for my simulink embeded function. However I would like to compute a variable size element inside the function, (only used for calculation). Therefore I would prefer not to declare the block as receiving or sending…
Chewbaka
  • 184
  • 10
1 2
3