variable-length

What is best way to implement variable length arrays?

I want to store a large result set from database in memory. Every record has variable length and access time must be as fast as arrays. What is the best way to implement this? I was thinking of keeping offsets in a separate table and storing all of the records consecutively? Is it odd? (Programming Language: Delphi) ...

Variable Sized Struct C++

Is this the best way to make a variable sized struct in C++? I don't want to use vector because the length doesn't change after initialization. struct Packet { unsigned int bytelength; unsigned int data[]; }; Packet* CreatePacket(unsigned int length) { Packet *output = (Packet*) malloc((length+1)*sizeof(unsigned int)); ...

Variable length template arguments list?

I remember seing something like this being done: template <ListOfTypenames> class X : public ListOfTypenames {}; that is, X inherits from a variable length list of typenames passed as the template arguments. This code is hypothetical, of course. I can't find any reference for this, though. Is it possible? Is it C++0x? ...

Matrix of unknown length in MATLAB?

I'm trying to set up a zero matrix of variable length with two columns into which I can output the results of a while loop (with the intention of using it to store the step data from Euler's method with adjusted time-steps). The length will be determined by the number of iterations of the loop. I'm wondering if there's a way I can do t...

Difference between variable-length argument and function overloading

This C++ question seems to be pretty basic and general but still I want someone to answer. 1) What is the difference between a function with variable-length argument and an overloaded function? 2) Will we have problems if we have a function with variable-length argument and another same name function with similar arguments? ...

C++ as in Java?: vector of vectors with *variable* length of int

My model would best use some v int[30][i][N_i]; structure that is 30 vectors of tuples of ints, where v[0] is a dummy, v[1] are plain ints (N_0 of them), v[2] are pairs of int (N_1 pairs) ... v[29] would be 29-tuples of int (N_29 of them) This is not vector<vector<int>> like in "generic-vector-of-vectors-in-c" Apparently, the out...

variable-length arrays

Hi, I just wonder if there is some overhead of using variable-length arrays? Can the size of array could be passed via command line argument at run time? Why is it introduced, compared to automatic and dynamically allocating an array? Thanks! ...

Two-dimensional variable-length array in Cobol

How do you go about defining a two-dimensional MxN array in Cobol of which both M and N are of variable length? Here's the message I get in Net Express when attempting to have a variable array inside another: COBCH0144S OCCURS DEPENDING subsidiary to OCCURS only allowed with ODOSLIDE ...

Most compact way to encode a sequence of random variable length binary codes?

Let's say you have a List<List<Boolean>> and you want to encode that into binary form in the most compact way possible. I don't care about read or write performance. I just want to use the minimal amount of space. Also, the example is in Java, but we are not limited to the Java system. The length of each "List" is unbounded. Therefo...

How to implement a variable-length ‘string’-y in C

I’ve googled quite a bit, but I can’t find information on how variable-length strings are generally implemented in higher-level languages. I’m creating my own such language, and am not sure where to start with strings. I have a struct describing the string type, and then a create function that allocates such a ‘string’: /* A safer `str...

Reading a Struct Within a Struct via PHP's Unpack Function.

I want to know how to read a struct within a struct via php's unpack function. When I get an IS_MCI packet, I check it's Type to make sure it's equal to ISP_MCI, and then I check NumC to find out how many CompCar structs there are within this packet. The problem is trying to unpack these contents into an array via a single function. I al...

C++ qsort array of pointers not sorting

Hi, I am trying to sort a buffer full of variable-length records alphabetically in C++. I previously asked how to implement this, and was told to sort an array of pointers to the records. I set up an array of pointers, but realized that each pointer points to the beginning of a record, but there is no way of it knowing when the record s...

Objective-c - Passing in variables to a variable-length method

I've got an array with items, and I want to pass these in to a variable-length method. How do you do that? I.e., I've got this (for example): NSArray *array = [NSArray arrayWithObjects:@"1", @"2", @"3", nil]; [[UIAlertView alloc] initWithTitle:@"title" message:@"message" delegate:nil cancelButtonTitle:[array objectAtIndex:0] otherButt...

How to create a variadic (with variable length argument list) function wrapper in JavaScript

The intention is to build a wrapper to provide a consistent method of calling native functions with variable arity on various script hosts - so that the script could be executed in a browser as well as in the Windows Script Host or other script engines. I am aware of 3 methods of which each one has its own drawbacks. eval() method: fu...

Are variable length arrays possible with Javascript

I want to make a variable length array in Javascript. Is this possible. A quick google search for "Javascript variable length array" doesn't seem to yield anything, which would be surprising if it were possible to do this. Should I instead have a String that I keep appending to with a separator character instead, or is there a better w...

Variable length Blob in hibernate?

I have a byte[] member in one of my persistable classes. Normally, I'd just annotate it with @Lob and @Column(name="foo", size=). In this particular case, however, the length of the byte[] can vary a lot (from ~10KB all the way up to ~100MB). If I annotate the column with a size of 128MB, I feel like I'll be wasting a lot of space for t...

What does (int (*)[])var1 stand for?

Hi, I found this example code and I tried to google what int (*)[])var1 could stand for, but I got no usefull results. #include <unistd.h> #include <stdlib.h> int i(int n,int m,int var1[n][m]) { return var1[0][0]; } int example() { int *var1 = malloc(100); return i(10,10,(int (*)[])var1); } Normally I work with VLAs in...

Parsing String into multiple variable length String (C#)

I am currently trying to convert a VB6 program into C#. There was extensive use of string splitting into structure. For example, Dim Sample AS String Sample = "John Doe New York Test Comment" Public Type Struct1 Name As String * 15 Address As String * 10 Comment As String * 20 End Type Dim dataStruct As Struct1 Se...

Freeing variable-sized struct in C

I am using a variable-sized C struct, as follows: typedef struct { int num_elems; int elem1; } mystruct; // say I have 5 elements I would like to hold. mystruct * ms = malloc(sizeof(mystruct) + (5-1) * sizeof(int)); ms->num_elems = 5; // ... assign 5 elems and use struct free(ms); Will this last free() free every...

Sending Variable-Length Data Over TCP Socket

My application needs to send/receive xml data via a tcp socket. There is no way to include any kind of a fixed-length header containing message length. As far as I understand, data transmitted over tcp can come to the receipient like this. <messa ge><content >hi</content> </message> But somehow this never happens meaning that data s...