help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Unexpected OCTAVE_LOCAL_BUFFER behavior


From: Mike Miller
Subject: Re: Unexpected OCTAVE_LOCAL_BUFFER behavior
Date: Tue, 07 Jan 2014 01:53:57 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20131103 Icedove/17.0.10

On Mon, 6 Jan 2014 20:16:56 -0800, mpender wrote:
> I'm trying to use the C++ function call OCTAVE_LOCAL_BUFFER for the first
> time and it is not behaving as I would expect.  However, this may or may not
> be a bug, and I don't want to submit a bug report since this may simply be
> my inexperience with the way the function actually works or an error in my
> pointer syntax.
> 
> I wrote a short Octave script that calls an oct file which reserves memory
> by two different methods.  The first uses a Matrix constructor and the
> second uses the OCTAVE_LOCAL_BUFFER call.  Then I assign the buffer to a
> global variable so I can keep the buffer accessible after returning from the
> oct file.  The Matrix constructor appears to work correctly, but the
> OCTAVE_LOCAL_BUFFER call always returns a scalar with the value 1.  The
> Octave script, oct file code and run results are as follows:

My understanding is that OCTAVE_LOCAL_BUFFER is intended for locally
scoped temporary buffers, not for allocating persistent memory. When the
variable (the 2nd macro argument) goes out of scope, the memory for the
buffer is freed. Attempting to assign it to a global variable and then
letting the buffer free itself is probably not a good idea.

I'm not familiar with set_global_value, but it looks like it takes an
argument of type octave_value. I don't know if there is an implicit
conversion from a pointer or an octave_local_buffer to an octave_value.

-- 
mike


reply via email to

[Prev in Thread] Current Thread [Next in Thread]