aboutsummaryrefslogtreecommitdiff
path: root/externals/grill/flext/source
diff options
context:
space:
mode:
authorThomas Grill <xovo@users.sourceforge.net>2003-11-29 03:41:26 +0000
committerThomas Grill <xovo@users.sourceforge.net>2003-11-29 03:41:26 +0000
commitdf40bd59509b30e24353946e89e90bbf9790cafa (patch)
treeee9ab818a080be1963a4b37ac26bda4e48088983 /externals/grill/flext/source
parentc94409c4b7a90e8c16f6e5b08f1b8522b7ee71fe (diff)
""
svn path=/trunk/; revision=1201
Diffstat (limited to 'externals/grill/flext/source')
-rw-r--r--externals/grill/flext/source/flbuf.cpp4
-rw-r--r--externals/grill/flext/source/fldsp.cpp2
-rw-r--r--externals/grill/flext/source/flsupport.cpp59
-rw-r--r--externals/grill/flext/source/flsupport.h18
4 files changed, 56 insertions, 27 deletions
diff --git a/externals/grill/flext/source/flbuf.cpp b/externals/grill/flext/source/flbuf.cpp
index e9c02a00..46eb7f4f 100644
--- a/externals/grill/flext/source/flbuf.cpp
+++ b/externals/grill/flext/source/flbuf.cpp
@@ -194,7 +194,7 @@ void flext::buffer::Frames(int fr,bool keep,bool zero)
if(keep) {
// copy buffer data to tmp storage
- tmp = new t_sample[sz];
+ tmp = (t_sample *)NewAligned(sz*sizeof(t_sample));
if(tmp)
CopySamples(tmp,data,sz);
else
@@ -215,7 +215,7 @@ void flext::buffer::Frames(int fr,bool keep,bool zero)
if(tmp) {
// copy data back
CopySamples(data,tmp,sz);
- delete[] tmp;
+ FreeAligned(tmp);
if(zero && sz < fr) ZeroSamples(data+sz,fr-sz);
}
else
diff --git a/externals/grill/flext/source/fldsp.cpp b/externals/grill/flext/source/fldsp.cpp
index c5d6ea22..b8dce7ca 100644
--- a/externals/grill/flext/source/fldsp.cpp
+++ b/externals/grill/flext/source/fldsp.cpp
@@ -16,8 +16,6 @@ WARRANTIES, see the file, "license.txt," in this distribution.
#include "flinternal.h"
#include <string.h>
-
-
// === flext_dsp ==============================================
#if FLEXT_SYS == FLEXT_SYS_JMAX
diff --git a/externals/grill/flext/source/flsupport.cpp b/externals/grill/flext/source/flsupport.cpp
index f8c6fac2..a77726ae 100644
--- a/externals/grill/flext/source/flsupport.cpp
+++ b/externals/grill/flext/source/flsupport.cpp
@@ -88,20 +88,26 @@ void flext::Setup()
//
/////////////////////////////////////////////////////////
+#define LARGEALLOC 32000
+
void *flext_root::operator new(size_t bytes)
{
bytes += sizeof(size_t);
-#ifdef FLEXT_DEBUG
- if(bytes > 32000)
- post("flext - warning: excessive memory allocation of %i bytes",bytes);
-#endif
+ char *blk;
+ if(bytes >= LARGEALLOC) {
+ // use C library function for large memory blocks
+ blk = (char *)::operator new(bytes);
+ }
+ else {
+ //! \todo We need system locking here for secondary threads!
#if FLEXT_SYS == FLEXT_SYS_JMAX
- char *blk = (char *)::fts_malloc(bytes);
+ blk = (char *)::fts_malloc(bytes);
#else
- char *blk = (char *)::getbytes(bytes);
+ blk = (char *)::getbytes(bytes);
#endif
+ }
*(size_t *)blk = bytes;
return blk+sizeof(size_t);
@@ -110,13 +116,21 @@ void *flext_root::operator new(size_t bytes)
void flext_root::operator delete(void *blk)
{
char *ori = (char *)blk-sizeof(size_t);
+ size_t bytes = *(size_t *)ori;
+
+ if(bytes >= LARGEALLOC) {
+ // use C library function for large memory blocks
+ ::operator delete(ori);
+ }
+ else {
+ //! \todo We need system locking here for secondary threads!
#if FLEXT_SYS == FLEXT_SYS_JMAX
- fts_free(ori);
+ fts_free(ori);
#else
- size_t bytes = *(size_t *)ori;
- ::freebytes(ori,bytes);
+ ::freebytes(ori,bytes);
#endif
+ }
}
void *flext_root::NewAligned(size_t bytes,int bitalign)
@@ -125,11 +139,20 @@ void *flext_root::NewAligned(size_t bytes,int bitalign)
const unsigned long alignovh = bitalign/8-1;
bytes += ovh+alignovh;
+ char *blk;
+ if(bytes >= LARGEALLOC) {
+ // use C library function for large memory blocks
+ blk = (char *)::operator new(bytes);
+ }
+ else {
+ //! \todo We need system locking here for secondary threads!
+
#if FLEXT_SYS == FLEXT_SYS_JMAX
- char *blk = (char *)::fts_malloc(bytes);
+ blk = (char *)::fts_malloc(bytes);
#else
- char *blk = (char *)::getbytes(bytes);
+ blk = (char *)::getbytes(bytes);
#endif
+ }
char *ablk = reinterpret_cast<char *>((reinterpret_cast<unsigned long>(blk)+ovh+alignovh) & ~alignovh);
*(char **)(ablk-sizeof(size_t)-sizeof(char *)) = blk;
@@ -140,13 +163,21 @@ void *flext_root::NewAligned(size_t bytes,int bitalign)
void flext_root::FreeAligned(void *blk)
{
char *ori = *(char **)((char *)blk-sizeof(size_t)-sizeof(char *));
+ size_t bytes = *(size_t *)((char *)blk-sizeof(size_t));
+
+ if(bytes >= LARGEALLOC) {
+ // use C library function for large memory blocks
+ ::operator delete(ori);
+ }
+ else {
+ //! \todo We need system locking here for secondary threads!
#if FLEXT_SYS == FLEXT_SYS_JMAX
- fts_free(ori);
+ fts_free(ori);
#else
- size_t bytes = *(size_t *)((char *)blk-sizeof(size_t));
- ::freebytes(ori,bytes);
+ ::freebytes(ori,bytes);
#endif
+ }
}
// ------------------------------------------
diff --git a/externals/grill/flext/source/flsupport.h b/externals/grill/flext/source/flsupport.h
index e8328ea3..2541e243 100644
--- a/externals/grill/flext/source/flsupport.h
+++ b/externals/grill/flext/source/flsupport.h
@@ -54,13 +54,6 @@ public:
void operator delete[](void *blk) { operator delete(blk); }
#endif
- /*! Get a large memory block
- the normal C library function is used here
- */
- static void *NewLarge(size_t bytes) { return ::operator new(bytes); }
- //! Free a large memory block
- static void FreeLarge(void *blk) { ::operator delete(blk); }
-
//! Get an aligned memory block
static void *NewAligned(size_t bytes,int bitalign = 128);
//! Free an aligned memory block
@@ -69,11 +62,18 @@ public:
static bool IsAligned(void *ptr,int bitalign = 128) {
return (reinterpret_cast<unsigned long>(ptr)&(bitalign-1)) == 0;
}
-
//! @} FLEXT_S_MEMORY
-
};
+// define global new/delete operators
+inline void *operator new(size_t bytes) { return flext_root::operator new(bytes); }
+inline void operator delete(void *blk) { flext_root::operator delete(blk); }
+#ifndef __MRC__ // doesn't allow new[] overloading?!
+inline void *operator new[](size_t bytes) { return flext_root::operator new[](bytes); }
+inline void operator delete[](void *blk) { flext_root::operator delete[](blk); }
+#endif
+
+
class FLEXT_SHARE FLEXT_CLASSDEF(flext);
typedef class FLEXT_CLASSDEF(flext) flext;