I see this in code sometimes:
struct S
{
int count; // length of array in data
int data[1];
};
Where the storage for S is allocated bigger than sizeof(S) so that data can have more space for its array. It is then used like:
S *s;
// allocation
s->data[3] = 1337;
My question is, why is data not a pointer? Why the length-1 ...
per the debate in this post: json-conversion-in-javascript
...
If I wanted to get a list of product_ids with a certain brand. I would do this:
$id_list = array();
$qry = 'SELECT product_id FROM products WHERE product_brand = :brand';
$STH = $this->pdo->prepare($qry);
$STH->execute(array("brand" => $brand));
$STH->setFetchMode(PDO::FETCH_ASSOC);
while($row = $STH->fetch())
{
$id_list[] = $row['p...
I have an array of arrays like this:
$cart = Array (
[0] => Array ( [TypeFlag] => S [qty] => 2 [denom] => 50 [totalPrice] => 100 )
[1] => Array ( [TypeFlag] => V [qty] => 1 [denom] => 25 [totalPrice] => 25 )
[2] => Array ( [TypeFlag] => C [qty] => 1 [denom] => 25 [totalPrice] => 25 )
)
Is there any way, short of looping throug...
I have a python script that successfully loads a csv file into a 2d numpy array and which then successfully extracts the value of a desired cell based on its column and row header values. For diagnostic purposes, I have the script print the contents of the data matrix before it is put into a numpy array. The script works when the data ...
I am trying to understand a little more about memory management. Knowing that I need to release anything that I have init or alloc'ed I am confused about the following:
- (NSMutableArray *)getData {
NSMutableArray *data = [[NSMutableArray alloc] init];
NSString *first = @"First object";
[data addObject:first];
NSString ...
I want to find a way to only allow certain objects into an array that have a certain word in thier class name. Or at least find the optimal way of doing something like this. Heres the details. I have an Array that stores all the objects dropped into a cart.
function addProductToArray (e:MouseEvent):void{
currMC = (e.target as MovieClip...
How do you add an value with an => $key into an array, for example:
$images = array();
array_push($images, $_FILES['file']['tmp_name'] => $_FILES['file']['name']);
So the array would be like:
array('temporary_file_name' => 'file_name.zip');
But my IDE says it's invalid and would not work.
...
I have an array in php like this :
Array
(
[0] => Array
(
[915] => 1
[1295] => 1
[1090] => 1
[1315] => 0.93759357774
[128] => 0.93759357774
[88] => 0.731522789561
[1297] => 0.731522789561
[1269] => 0.525492880722
...
I'm learning Ruby, and have just gotten into some stuff about arrays and ranges. I've run into something about slices that, while it makes sense at first glance, confuses me a bit when i look deeper into it.
irb says that (2..-1).to_a is an empty array. Meaning no values in the range, right?
But if i use that same range in [:a, :b, :c...
Java.
I have a very small int array (4 elements).
What's the fastest way to get max value? All values will be between 0 and 255.
Also int array is faster than byte array? Is casting much of a hit?
What's the fastest way to get sum of all values?
The reason I ask is cause this is a major bottleneck in a program I inherited. They a...
I'm working on a little server app with Java. So, I'm getting informations from different client, and if information comes in, the following method is called:
public void writeToArray(String data) {
data = trim(data);
String[] netInput = new String[5];
netInput[0]="a";
netInput[1]="a";
netInput[2]="a";
netInput[3...
In my Windows Mobile (.NET Compact Framework) application I use a big array to store the application's primary data. This is a dataset of potentially hundreds of objects. Each object has about 10 or so properties and two arrays of itself, each with about 25 other objects, each of which has about 5 properties.
To save this array on the m...
Hello,
I am creating a uiscrollview programmatically populated with multiple uitableviews.
The uitableviews need a manual datasource that will change for every instance. I
wondered if any of you have some sample code of an array of uitableviews where
cells are configured.
Thanks in advance for your help!
...
I need to access SecureRandom Java Object from Javascript. My ultimate goal is to grab 4 bytes from PRNG and convert it to Javascript integer variable. According to http://download.oracle.com/javase/1.4.2/docs/api/java/security/SecureRandom.html, the following two lines of Java code are supposed to do grab 4 random bytes:
byte bytes[] ...
The problem I've just faced is what to do in the following case:
func printItems(header string, items []interface{}, fmtString string) {
// ...
}
func main() {
var iarr = []int{1, 2, 3}
var farr = []float{1.0, 2.0, 3.0}
printItems("Integer array:", iarr, "")
printItems("Float array:", farr, "")
}
Go has no generics and does...
Is there a function in javascript to do this - test if a given value (a string in my case) exists in an array (of strings)? I know I could just loop over each value, but I'm wondering if js has a shorthand for this.
...
Hi.
consider the following code:
void Increment(int *arr) {
arr++;
}
int main() {
int arr[] = {1,2,3,4,5};
// arr++ // illegal because its a const pointer
Increment(arr); // legal
}
My question is if arr is a const pointer, how come i can send it to a function that doesn't receive a const pointer?
The code compile...
I am kinda new to this, but I am trying to fill an array from a sql statement that pulls several permit numbers from a table.
So in the table every person can have multiple permits, I need to store all the permit numbers and display them in a drop down box via javascript. I have been able to get at least the first permit, but nothing a...
Im trying to find a solution for this problem. This is my example code:
class Program
{
private string Command;
private static string[] Commands = { "ComandOne", "CommandTwo", "CommandThree", "CommandFour" };
static void Main(string[] args)
{
Command = args[0];
switch(Command)
{
case Commands[0]: //do someth...