// An object which contains samples
-
+#include "bcresources.h"
+#include "bcwindowbase.h"
#include "samples.h"
#include <stdio.h>
#include <sys/shm.h>
Samples::Samples(Samples *src)
{
reset();
- share(src->get_shmid());
- set_allocated(src->get_allocated());
+ int src_sz = src->get_allocated();
+ if( use_shm ) {
+ share(src->get_shmid());
+ set_allocated(src_sz);
+ }
+ else {
+ share(src->data);
+ set_allocated(0);
+ }
set_offset(src->get_offset());
}
void Samples::reset()
{
- use_shm = 1;
+ BC_Resources *resources = BC_WindowBase::get_resources();
+ use_shm = !resources || !resources->use_shm ? 0 : 1;
shmid = -1;
data = 0;
allocated = 0;
{
if(data) shmdt(data);
}
- else
+ else if( allocated )
{
delete [] data;
}
this->allocated = 0;
this->shmid = shmid;
}
+void Samples::share(double *buffer)
+{
+ if(data)
+ {
+ if(use_shm)
+ shmdt(data);
+ else
+ delete [] data;
+ }
+ this->use_shm = 0;
+ data = buffer;
+ this->allocated = 0;
+ this->shmid = -1;
+}
+
void Samples::allocate(int samples, int use_shm)
{
- if(data &&
+ if( !this->use_shm ) use_shm = 0;
+ if( data &&
this->allocated >= samples &&
- this->use_shm == use_shm) return;
+ this->use_shm == use_shm ) return;
- if(data)
- {
- if(this->use_shm)
+ if( data ) {
+ if( this->use_shm )
shmdt(data);
else
delete [] data;
this->use_shm = use_shm;
- if(use_shm)
- {
+ if( use_shm ) {
shmid = shmget(IPC_PRIVATE,
(samples + 1) * sizeof(double),
IPC_CREAT | 0777);
// This causes it to automatically delete when the program exits.
shmctl(shmid, IPC_RMID, 0);
}
- else
- {
+ else {
shmid = -1;
data = new double[samples];
}
-
this->allocated = samples;
-
-
-
-
}
// Get the buffer