Coder Social home page Coder Social logo

arralloc's Introduction

Arralloc

Arralloc allocates an N dimensional array that can be accessed using square braces.

It also allows the array do be dereferenced to provide a flattened array of data where storage conventions follow regular C conventions.

Finally, the entire array has been allocated with one call to malloc, so it can be freed using one call to free.

Example Usage:

int ***arr3d = arralloc(sizeof(int), 3, 6,7,8);

/* Array accessible and settable using [i][j][k] */
for(i=0; i<6; i++)
for(j=0; j<7; j++)
for(k=0; k<8; k++) {
    arr3d[i][j][k] = i*7*8 + j*8 + k;
}

/* Access a flattned array of the data */
int *flat = &arr3d[0][0][0];

for(i=0; i<6; i++)
for(j=0; j<7; j++)
for(k=0; k<8; k++) {
    /* Will print (i*7*8 + j*8 + k) */
    printf("%d\n", flat[i*7*8 + j*8 + k]);
}

/* Free the entire array plus pointer arrays */
free(arr3d);

arralloc's People

Contributors

poconbhui avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.