1,877 questions
2
votes
3
answers
465
views
Associative array with mixed (numerical and string) indices?
How would one implement a dynamic associative array that could take any number of mixed indices (integers, strings, or both)?
I aim to simulate structures by providing, for example, people[3]....
16
votes
2
answers
13k
views
Is a dynamic array automatically deallocated when it goes out of scope?
in this example
procedure foobar;
var tab:array of integer;
begin
setlength(tab,10);
end;
is the array destroyed or the memory is leaking?
0
votes
3
answers
5k
views
how to Clean up(destructor) a dynamic Array of pointers?
Is that Destructor is enough or do I have to iterate to delete the new nodes??
#include "stdafx.h"
#include<iostream>
using namespace std;
struct node{
int row;
int col;
...
1
vote
2
answers
4k
views
How to create multi-dimensional jagged arrays in VbScript?
I need to create multi-dimensional array of strings. Each row of the array can have varying number of strings. Something like the follwing code:
twoDimension = Array(Array())
ReDim Preserve ...
6
votes
4
answers
3k
views
Can I use the [] operator in C++ to create virtual arrays
I have a large code base, originally C ported to C++ many years ago, that is operating on a number of large arrays of spatial data. These arrays contain structs representing point and triangle ...
6
votes
4
answers
1k
views
Delphi SetLength Custom Indexing
In Delphi, it is possible to create an array of the type
var
Arr: array[2..N] of MyType;
which is an array of N - 1 elements indexed from 2 to N.
If we instead declare a dynamic array
var
Arr: ...
3
votes
2
answers
937
views
Accessing the _CopyArray procedure
Is there a way to access (and call) procedures like _CopyArray that are defined in the interface in the unit System?
NB: I am trying to create a routine that makes a deep clone of any dynamic array, ...
10
votes
7
answers
14k
views
TStringList, Dynamic Array or Linked List in Delphi?
I have a choice.
I have a number of already ordered strings that I need to store and access. It looks like I can choose between using:
A TStringList
A Dynamic Array of strings, and
A Linked List of ...
3
votes
3
answers
2k
views
Issue with dynamic array Queue data structure with void pointer
Maybe there's no way to solve this the way I'd like it but I don't know everything so I better ask...
I've implemented a simple Queue with a dynamic array so the user can initialize with whatever ...
0
votes
2
answers
1k
views
Access Violation When Writing Dynamic 2D Array... Sometimes
This program is meant to generate a dynamic array, however it gives an access violation error when writing when given certain dimensions. Eg: R = 6, C = 5 crashes, but then R = 5, C = 6 doesn't. In ...
11
votes
4
answers
2k
views
Why does C++ allow variable length arrays that aren't dynamically allocated? [duplicate]
I'm relatively new to C++, and from the beginning it's been drilled into me that you can't do something like
int x;
cin >> x;
int array[x];
Instead, you must use dynamic memory. However, I ...
3
votes
4
answers
444
views
How to define a static array without a contant size in a constructor of a class? (C++)
I have a class defined as:
class Obj {
public:
int width, height;
Obj(int w, int h);
}
and I need it to contain a static array like so:
int presc[width][height];
however, I cannot define ...
3
votes
3
answers
4k
views
Writing and reading struct with dynamic array through a pipe in C
I have a struct with a dynamic array inside of it:
struct mystruct {
int count;
int *arr;
} mystruct_t;
and I want to pass this struct down a pipe in C and around a ring of processes. When I alter ...
1
vote
4
answers
3k
views
Cleaning up a dynamic array of Objects in C++
I'm a bit confused about handling an array of objects in C++, as I can't seem to find information about how they are passed around (reference or value) and how they are stored in an array.
I would ...
1
vote
5
answers
3k
views
Finding dimensions of a 2D array in C using pointers
I create a 2D array in C as follows:
int **arr;
arr = malloc(rows * sizeof(int *));
for (i = 0; i < rows; i++)
arr[i] = malloc(cols * sizeof(int));
Now, I call:
func(arr)
In the function ...
5
votes
7
answers
10k
views
C# Increasing an array by one element at the end
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 ...
1
vote
4
answers
2k
views
Java Null Pointer Exception
I attempted to adapt a class I had found on the web for a dynamic array of ints for a dynamic array of "Entities," but now I am getting a "NullPointerException."
The code raising the exception is:
...
4
votes
3
answers
630
views
What bookkeeping data does a Delphi dynamic array contain?
Here's a simple program to check memory allocation. Checking before and after values with Task Manager suggests that each dynamic array takes up 20 bytes of memory at size = 1. The element size is 4,...
0
votes
1
answer
428
views
How to use _spawn or _exec for bootstrapping?
After writing the following program, it does not appear to pass arguments to the called application. While researching _spawnv and what it can do, _execvp was found as what appeared to be a suitable ...
1
vote
4
answers
229
views
C++ - is a pointer to a single value same as a size 1 dynamic array?
I have this snippet of code which I am considering to simplfy:
if (numberOfResults > 1)
{
trackResult_ = new TrackResult[numberOfResults];
for (int i=0; i < numberOfResults; i++)
...
12
votes
1
answer
7k
views
How to "watch" a C++ dynamic array using gdb?
Consider the following example:
int size = 10, *kk = new int[size];
for (int i = 0; i < size; i++) {
kk[i] = i;
}
delete [] kk;
How can I add a watch for the whole array? I can add a watch ...
1
vote
9
answers
3k
views
C++ Array size x86 and for x64
Simple question, I'm writting a program that needs to open huge image files (8kx8k) but I'm a little bit confused on how to initialize the huge arrays to hold the images in c++.
I been trying ...
0
votes
6
answers
3k
views
C++ Dynamic Array Access Violation
**** Sorry for the confusion regarding numCars in the original post. I modified the code to be consistent with the original ******
The following academic program is a simplified version of the ...
2
votes
4
answers
2k
views
C++ dynamically allocated array of statically dimensioned arrays
I need to create a structure that holds a variable number of 'char[2]'s, i.e. static arrays of 2 chars.
My question is, how do I allocate memory for x number of char[2].
I tried this (assuming int x ...
1
vote
4
answers
2k
views
Problems deleting a 2D dynamic array in C++ (which is eventually store in a vector)
So I have this 2d dynamic array which content I want to free when I am done with it. However I keep running into a heap corruption after the destructor. The code works fine (of course with memory ...
119
votes
12
answers
34k
views
What is the ideal growth rate for a dynamically allocated array?
C++ has std::vector and Java has ArrayList, and many other languages have their own form of dynamically allocated array. When a dynamic array runs out of space, it gets reallocated into a larger area ...
37
votes
2
answers
87k
views
How do I declare an array when I don't know the length until run time?
I originally had an array[1..1000] that was defined as a global variable.
But now I need that to be n, not 1000 and I don't find out n until later.
I know what n is before I fill the array up but I ...