New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resizing an fvec_t #230
Comments
hi @Lord-Kamina Yes, Here is an example of creating an fmat_t *m = new_fmat(2, 16); // allocate a new matrix
fvect_t v; // created on the stack
v.length = 8; // set its length
v.data = m->data[1] + 8; // point to start of data
// &v is now ready to use as any other vector
fvec_ones(&v); // fill our 'vector'
fmat_print(m); // the content of m has changed
// clean-up
del_fmat(m); // nothing else to delete Of course you will want to make sure read/write out-of-bounds accesses and double free are prevented when writing this kind of code. Let us know if this answers your question! cheers, piem |
@piem thanks, but not really. What I want to know is if for example doing something like: fvec_t* vec = new_fvec(4);
vec->length = 8;
vec[5] = 1.0; Is safe to do? Sent with GitHawk |
hi @Lord-Kamina No, that program should fail, since You are probably best to allocate all the memory required for your program at start time, then use the example provided above. cheers, piem |
Hi @Lord-Kamina Closing this issue now, I hope it answered your questions. best, piem |
Is it at all recommended to do this? I've seen examples of code that just changes the "length" value for an
fvec_t
but AFAICT, without really resizing the array, that could only result in aubio trying to use memory containing something else?The text was updated successfully, but these errors were encountered: