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
2
votes
1 answer

NaN or Inf arrays preallocation

Array indexing can be used for efficient array preallocation. For instance 2(ones(1, 3)) ans = 2 2 2 but this does not work with NaN or Inf NaN(ones(1, 3)) ans = NaN Why ?
ederag
  • 2,409
  • 25
  • 49
1
vote
1 answer

Matlab class properties as handles, nested handles and class initialization/constructor and preallocation

I have been wondering how user defined Matlab classes as handle subclasses works. It seems, and also from what I read, that in some cases they reference to each other that might be unexpected or misleading and causing bugs. I have encountered this…
Vaclav
  • 21
  • 2
1
vote
1 answer

Preallocating memory for variable that changes size every iteration (long text file)

I wrote a code which translates an image to text file for lithography. The images are high resolution (26.5k x 26.5k) and the text files are over 2MB. My problem is that it takes very long for the code to work and I suspect it has something to do…
1
vote
2 answers

How to disable mongod journal pre-allocation

Is there a way to prevent mongod from pre-allocating these 100 MB files in journal folder? WiredTigerPreplog.0000000001 WiredTigerPreplog.0000000002 I want journaling to be enabled.
Daniel
  • 161
  • 2
  • 11
1
vote
5 answers

Declaring a vector in matlab whose size we don't know

Suppose we are running an infinite for loop in MATLAB, and we want to store the iterative values in a vector. How can we declare the vector without knowing the size of it? z=?? for i=1:inf z(i,1)=i; if(condition)%%condition is met then break…
Kivtas
  • 27
  • 1
  • 6
1
vote
0 answers

Efficiently way of assembling PyTorch `Tensor`s that require gradients

I need to construct a 4-dimensional PyTorch Tensor where one of the dimensions comes from multiplying a constant sparse matrix with a dense vector. The dense vector, and the resulting 4D Tensor, require gradients to be tracked. Since PyTorch only…
gspr
  • 11,144
  • 3
  • 41
  • 74
1
vote
1 answer

Queued Message Handler VIs in parent SubVI which execution type is set to be as preallocated (?)

I am creating an sample of a communication server through LabVIEW. In the main VI I have a server and clients: Execution of the last is set as preallocated clone reentrant. I use Queued Message Handler to transfer messages and commands between…
Henrik
  • 159
  • 1
  • 15
1
vote
1 answer

How to pre-allocate a structure vector in Matlab

In matlab, the function struct allow to pre-allocate a structure like this S = struct(field1,{},field2,{},...,fieldN,{}) But I need S to be a vector of structures of let's say a length of 100, and I don't know how to do that. I want to do this so…
Pedro
  • 135
  • 4
1
vote
1 answer

Does preallocate clone only allocate one clone if a VI is in a FOR loop?

I'm going through the sample exam papers in advance of sitting the CLD-R. I came across the reentrancy question shown below: The answer is 4. There is no specific mention of preallocation in a for loop in the documentation. The "preallocating"…
SeanJ
  • 1,203
  • 2
  • 19
  • 39
1
vote
1 answer

Why MATLAB keeps consuming memory when setting fields of a preallocated struct?

I'm reading frames of an AVI movie and doing some calculations on its frames. This is a part of my code: clear; clc; mov = mmreader('traffic.avi'); vidHeight = mov.Height; vidWidth = mov.Width; nFrames = mov.NumberOfFrames; patchsize =…
saastn
  • 5,717
  • 8
  • 47
  • 78
1
vote
3 answers

Progressive appending of data from read.csv

I want to construct a data frame by reading in a csv file for each day in the month. My daily csv files contain columns of characters, doubles, and integers of the same number of rows. I know the maximum number of rows for any given month and the…
Benjamin Levy
  • 333
  • 6
  • 19
0
votes
1 answer

how to preallocate a matrix in Matlab for a 'while' loop?

I want to preallocate a matrix in matlab to get rid of out of memory error, but how can i use preallocating for a while loop? we use preallocating for a for loop like this: m=10000; x=zeros(m,1) for i = 1:m x(i) = i end but what if i want to…
0
votes
0 answers

How to preallocate VideoWriter file in matlab

My code generates 10 videos in a for loop using the VideoWriter function. I know how to pre-allocate arrays but I am not sure how to make pre-allocation for VideoWriter files. writerObj file in the code below should be pre-allocated. for i=1:10 …
John
  • 37
  • 6
0
votes
0 answers

Preallocate memory for an unknown size of list in R

I am confused about the preallocation in R. We all know that preallocation will be much faster and it can solve the problems of over-memory. However, if we want to obtain a list with an unknown length, should we assign a much longer length? Or we…
rio
  • 9
  • 3
0
votes
3 answers

How to pre-allocate C# List of List of T

I'd like to pre-allocate a List>. I know I can pre-allocate 1-D Lists like this: List MyList = new List(SomeSize); Is it possible to do this for nested lists? In C++, I would do: vector>…
Matt Stein
  • 81
  • 6