Archive

Archive for May, 2013

array besar di c

May 5, 2013 Leave a comment

waktu itu mau coba alokasikan array di c, ukuran 500an kali 35000an.

langsung crash, hehehe. coba pake cara lain

bikin array of pointer dulu, terus masing2 baru deh dialokasikan pakai malloc.

ini contoh programnya.

 

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{
int width=600, height=40000;
int* foo[width];
int i;
for(i=0;i<width;i++) {
foo[i]=malloc(sizeof(int)*height);
}

foo[width-1][height-1]=5;
printf(“%d\n”, foo[width-1][height-1]);

for(i=0;i<width;i++) {
free(foo[i]);
}

printf(“end\n”);
}

Advertisements
Categories: Uncategorized