how best to resize array?
Hi, I am creating an array, but i don't know how big I need it to be at the time it is instantiated. Once I figure out what I want that size to be, how do I assign it? The current solution i have is this: int array[]; int size; // do stuff { // new block keeps dummy from clogging namespace int dummy[size]; dummy @=> array; } Is there a better way? Regards, George
On 27 July 2012 15:57, George Locke
Is there a better way?
Indeed. I'm a bit busy, so excuse the quoting; 1.2.1.2 - (added) dynamic, resizable arrays .size( int ) resizes array; .size() returns current size() << operator appends new elements into array .popBack() pops the last element of the array, reducing size by 1 .clear() zero's out elements of the array (see examples/array/ array_dyanmic.ck array_resize.ck) Source; http://chuck.cs.princeton.edu/release/VERSIONS Hope that helps, Kas.
Hi George,
You can check examples in Chuck installation directory: \examples\array\
array_resize.ck and array_dynamic.ck
Personally I use:
array.size(new_size);
or
array << new_element; // to add an element.
Happy chucking,
Julien
2012/7/27 George Locke
Hi,
I am creating an array, but i don't know how big I need it to be at the time it is instantiated. Once I figure out what I want that size to be, how do I assign it? The current solution i have is this:
int array[]; int size; // do stuff { // new block keeps dummy from clogging namespace int dummy[size]; dummy @=> array; }
Is there a better way?
Regards, George
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
thanks! On Fri, Jul 27, 2012 at 10:31 AM, Julien Saint-Martin < julien.saintmartin@googlemail.com> wrote:
Hi George,
You can check examples in Chuck installation directory: \examples\array\ array_resize.ck and array_dynamic.ck Personally I use: array.size(new_size); or array << new_element; // to add an element.
Happy chucking, Julien
2012/7/27 George Locke
Hi,
I am creating an array, but i don't know how big I need it to be at the time it is instantiated. Once I figure out what I want that size to be, how do I assign it? The current solution i have is this:
int array[]; int size; // do stuff { // new block keeps dummy from clogging namespace int dummy[size]; dummy @=> array; }
Is there a better way?
Regards, George
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
participants (3)
-
George Locke
-
Julien Saint-Martin
-
Kassen