dynamic-arrays

C# Increasing an array by one element at the end

旧时模样 提交于 2019-12-01 18:46:19
问题 In my program I have a bunch of growing arrays where a new element is grown one by one to the end of the array. I identified Lists to be a speed bottleneck in a critical part of my program due to their slow access time in comparison with an array - switching to an array increased performance tremendously to an acceptable level. So to grow the array i'm using Array.Resize. This works well as my implementation restricts the array size to approximately 20 elements, so the O(N) performance of

C# Increasing an array by one element at the end

跟風遠走 提交于 2019-12-01 18:44:28
In my program I have a bunch of growing arrays where a new element is grown one by one to the end of the array. I identified Lists to be a speed bottleneck in a critical part of my program due to their slow access time in comparison with an array - switching to an array increased performance tremendously to an acceptable level. So to grow the array i'm using Array.Resize. This works well as my implementation restricts the array size to approximately 20 elements, so the O(N) performance of Array.Resize is bounded. But it would be better if there was a way to just increase an array by one

What is the purpose of ANYSIZE_ARRAY in <winnt.h>?

巧了我就是萌 提交于 2019-12-01 17:57:56
What's the purpose of ANYSIZE_ARRAY , located in WinNT.h? I see an MSDN blog post about it from 2004 but it doesn't make sense to me. I assume you are talking about this blog post . It is often used when a variable-sized (unknown at compile time) array is part of a struct: typedef struct { int CommonFlags int CountOfThings; THING Things[ANYSIZE_ARRAY]; //Things[1]; } THINGSANDFLAGS; To work with those structures you often first call the desired API to get the size of the data, then allocate a block of memory big enough and finally call the same API again so it can fill in the data... From this

Does std::vector use the assignment operator of its value type to push_back elements?

为君一笑 提交于 2019-12-01 14:18:27
问题 If so, why? Why doesn't it use the copy constructor of the value type? I get the following error: /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/vector.tcc: In member functio n `ClassWithoutAss& ClassWithoutAss::operator=(const ClassWithoutAss&)': /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/vector.tcc:238: instantiate d from `void std::vector<_Tp, _Alloc>::_M_insert_aux(__gnu_cxx::__normal_iterato r<typename _Alloc::pointer, std::vector<_Tp, _Alloc> >, const _Tp&) [with _Tp =

What algorithm does Matlab use to dynamically resize vectors and matrices?

☆樱花仙子☆ 提交于 2019-12-01 06:49:43
Running this code: n = 5; x = zeros(n, 1); for ix=1:10 x(ix) = rand(); disp(getfield(whos('x'), 'bytes')) end outputs this: 40 40 40 40 40 48 56 64 72 80 which seems to indicate that when Matlab resizes a vector, it resizes it to have exactly as much space as it needs, no more. So, one element at a time. Contrast this with the method in Sun's Java implementation of ArrayList , which allocates enough space so that every resizing won't need to happen on every assignment above the initial bound. Obviously since Matlab isn't open source there's no way to tell 100% what they do, but is there a

What algorithm does Matlab use to dynamically resize vectors and matrices?

不问归期 提交于 2019-12-01 06:03:31
问题 Running this code: n = 5; x = zeros(n, 1); for ix=1:10 x(ix) = rand(); disp(getfield(whos('x'), 'bytes')) end outputs this: 40 40 40 40 40 48 56 64 72 80 which seems to indicate that when Matlab resizes a vector, it resizes it to have exactly as much space as it needs, no more. So, one element at a time. Contrast this with the method in Sun's Java implementation of ArrayList, which allocates enough space so that every resizing won't need to happen on every assignment above the initial bound.

int[n][m], where n and m are known at runtime

泄露秘密 提交于 2019-12-01 04:32:17
问题 I often need to create a 2D array with width and height (let them be n and m) unknown at compile time, usually I write : vector<int> arr(n * m); And I access elements manually with : arr[j * m + i] I recently got told that I could instead write : int arr[n][m] // n and m still only known at runtime. So here are 2 questions : Is this behaviour allowed by the C++ Standard ? How should I pass such an array to a function ? g++ reports that arr has type int (*)[n] , but again, n is dynamic and not

CUFFT : How to calculate the fft when the input is a pitched array

◇◆丶佛笑我妖孽 提交于 2019-11-30 16:20:48
I'm trying to find the fft of a dynamically allocated array. The input array is copied from host to device using cudaMemcpy2D . Then the fft is taken (cufftExecR2C) and the results are copied back from device to host. So my initial problem was how to use the pitch information in the fft. Then I found an answer here - CUFFT: How to calculate fft of pitched pointer? But unfortunately it doesn't work. The results I get are garbage values. Given below is my code. #define NRANK 2 #define BATCH 10 #include "cuda_runtime.h" #include "device_launch_parameters.h" #include <cufft.h> #include <stdio.h>

Dynamically allocated 2 dimensional array

眉间皱痕 提交于 2019-11-30 15:52:08
问题 I am trying to build two dimensional array by dynamically allocating. My question is that is it possible that its first dimension would take 100 values, then second dimension would take variable amount of values depending on my problem? If it is possible then how I would access it? How would I know the second dimension's boundary? 回答1: (See the comments in the code) As a result you'll get an array such like the following: // Create an array that will contain required variables of the required

VBA: Iteration speed of variant array vs. typed array vs. non-keyed collection

自闭症网瘾萝莉.ら 提交于 2019-11-30 14:46:20
问题 My project requires a bunch of dynamically-resizable arrays for different objects. An array may hold any number of objects, potentially thousands, of a single class, but not objects of multiple classes. Mostly I will be iterating through arrays, thus use of a keyed collection is not ideal. I think I have two options: The first option is to develop a 'List' class for each object type, with methods for adding objects (and expanding the array), getting the First and Last indexes and the object