[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: overloading the global new/delete operator in octave
From: |
Soeren Sonnenburg |
Subject: |
Re: overloading the global new/delete operator in octave |
Date: |
Mon, 03 Aug 2009 15:45:31 +0200 |
On Mon, 2009-08-03 at 00:13 -0700, Sergei Steshenko wrote:
>
>
> --- On Sun, 8/2/09, Soeren Sonnenburg <address@hidden> wrote:
>
> > From: Soeren Sonnenburg <address@hidden>
> > Subject: overloading the global new/delete operator in octave
> > To: "Octave users list" <address@hidden>
> > Date: Sunday, August 2, 2009, 11:45 AM
> > Dear all,
> >
> > I am a bit puzzled why my overloaded global new[] operator
> > does not
> > become effective when building a octave extension (it works
> > with
> > python/matlab though)...
[...]
> It's probably a (wrong) long shot, but try
>
> fprintf(stderr, "test\n");
>
> - you know, (un)buffered output. Experimentally stdout sometimes takes a
> lot of time/output to get flushed.
That was not the cause (and I still don't know what could potentially
cause it). However, I managed to create a an isolated toy example which
works just fine :-) So there could be a problem related to interactions
between the two libraries I link against (which in fact implement this
overloading...). Anyway working isolated example follows:
#include <octave/config.h>
#include <octave/ov.h>
#include <octave/defun-dld.h>
#include <stdio.h>
#include <new>
void* operator new(std::size_t size) throw (std::bad_alloc)
{
void *p=malloc(size);
fprintf(stderr, "alloc %p %lld\n", p, (long long int) size);
return p;
}
void operator delete(void *p)
{
fprintf(stderr, "free %p\n", p);
if (p)
free(p);
}
void* operator new[](std::size_t size) throw (std::bad_alloc)
{
void *p=malloc(size);
fprintf(stderr, "alloc[] %p %lld\n", p, (long long int) size);
return p;
}
void operator delete[](void *p)
{
fprintf(stderr, "free[] %p\n", p);
if (p)
free(p);
}
DEFUN_DLD (shogun, prhs, nlhs, "shogun.")
{
fprintf(stderr, "start\n");
volatile int* foo = new int[2];
delete[] foo;
fprintf(stderr, "end\n");
return octave_value_list();
}
Soeren
--
For the one fact about the future of which we can be certain is that it
will be utterly fantastic. -- Arthur C. Clarke, 1962
signature.asc
Description: This is a digitally signed message part