Dynamic allocation Of 2D arrays
Description: add to source, compile and run. very brief example usage (basically just the calling syntax) included in the comments two functions; the first dynamically allocates a 2D array with a user- or program-specified number of rows/columns; the second deallocates the same array. demonstrates the multi-dimensional usage of malloc and free. this snippet is also here: https://txeditor.com/jhn8gomb8g1
Code:
/* allocate2D |
Re: Dynamic allocation Of 2D arrays
I'm not sure if you're meant to have C code in SourceMod tutorials section, but regardless I'm just gonna say that I prefer using 1D array then mapping to 2D so that I don't get into the allocation aids. Just 1 malloc (size=width*height)/free and thats it.
Then to access an element at x/y you can do array[x + y*width] |
Re: Dynamic allocation Of 2D arrays
ArrayList of ArrayList?
|
| All times are GMT -4. The time now is 22:39. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.