Forums > Dev

sysmem_resizeptr crashes

April 12, 2011 | 3:46 pm

Hey,

I am trying to implement a solution for sending audio over network. My implementation should handle any number of channels, specified by the channel number(s) given as an argument to the external (similar to the way to create a [dac~])

For this I want to store the respective audio into a global handle, where each pointer in the handle points to a buffer for each channel of audio.

The buffers should have the size of the signal vector, as the whole handle containing all channels will be sent over the network.

The problem I have is, that whenever I call sysmem_resizeptr max crashes on me. I create a new sysmem_newptr on creation of each object in the handle position based on the argument given:

if (!handle) {
handle = sysmem_newhandle(2000);
post("I have a handle %lx and it is %ld bytes in size", handle, sysmem_handlesize(handle));
} else {
post("Handle %lx already exists", handle);
}

if (argc > 0) {
x->chan = atom_getlong(argv);
post("Using channel %ld", x->chan);
handle[x->chan] = sysmem_newptr(8192);
post("Created new pointer %lx of size %ld", handle[x->chan], sysmem_ptrsize(handle[x->chan]));
}

Am I missing something as of the point before calling sysmem_resizeptr? I tried calling it both in the dsp method (because, really, I need the vector size) and the new method, but no difference :(

Also, there is no other way to obtain the vector size, no? (It also makes sense, because the vector size can be changed during run-time making it necessary to call the dsp method again)

Would be great if anybody has experience with this.
Thanks!


April 13, 2011 | 7:02 am

Hi.

The point is, you’re treating a handle as if it was an array of pointers, but it’s not. It’s a pointer to a pointer, allocated in a way of its own so that in some cases you need to have an actual t_handle instead than a void **

If I were you, I’d give up using handles at all (btw, the documentation of the sdk advises against them), declare an array of pointers in your object structure fixing a maximum number of allowed channels – something like

#define MAX_CHANNELS 32
// ...
struct _myobject {
 // ...
 t_sample *my_audio[MAX_CHANNELS];
}

and then iterate on your array to allocate / resize / free each pointer according to your needs.

If you really need to be able to manage a very large number of channels, you should declare in your object structure
t_sample **my_audio;
and then manage the allocation, resizing and deallocation of memory associated to both my_audio and *my_audio.

hth
aa


Viewing 2 posts - 1 through 2 (of 2 total)