octave-bug-tracker
[Top][All Lists]
Advanced

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

[Octave-bug-tracker] [bug #48793] no need for OCTAVE_LOCAL_BUFFER anymor


From: Carnë Draug
Subject: [Octave-bug-tracker] [bug #48793] no need for OCTAVE_LOCAL_BUFFER anymore
Date: Mon, 15 Aug 2016 20:43:12 +0000 (UTC)
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0

URL:
  <http://savannah.gnu.org/bugs/?48793>

                 Summary: no need for OCTAVE_LOCAL_BUFFER anymore
                 Project: GNU Octave
            Submitted by: carandraug
            Submitted on: Mon 15 Aug 2016 08:43:10 PM GMT
                Category: None
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: None
                  Status: None
             Assigned to: None
         Originator Name: 
        Originator Email: 
             Open/Closed: Open
         Discussion Lock: Any
                 Release: dev
        Operating System: Any

    _______________________________________________________

Details:

Notes from an IRC discussion (I won'r have time to work on this anymore and
it's probably not suitable for Octave 4.2 anyway).

The main purpose of OCTAVE_LOCAL_BUFFER is to get a pointer to a data buffer
with RAII semantics.  There are comments that claim to have other
optimizations.  See
https://lists.gnu.org/archive/html/octave-maintainers/2008-12/msg00032.html

One of them is about allocating in the stack instead of the heap for small
chunks but that is actually disabled
http://hg.savannah.gnu.org/hgweb/octave/file/8192c26fcda4/liboctave/util/oct-locbuf.h#l174


#if 0 // defined (HAVE_DYNAMIC_AUTO_ARRAYS)


We can't use std::vector because its specialization for bool doesn't allow to
get "bool *".

std::unique_ptr is a better choice. On mtmx words:

> primary purpose of OCTAVE_LOCAL_BUFFER was to have very lightweight memory
buffer that just has a desctructor, so maybe the best alternative would be
std::unique_ptr<T> instead of std::vector<T>? or std::array<T> where the size
is completely fixed/known at compile time

I tried to do it with:


#define OCTAVE_LOCAL_BUFFER(T, buf, size)            \
  std::unique_ptr<T> _buffer_ ## buf (new T(size));  \
  T* buf = _buffer_ ## buf.get ();
 
 #define OCTAVE_LOCAL_BUFFER_INIT(T, buf, size, value) \
  OCTAVE_LOCAL_BUFFER(T, buf, size)                   \
  for (size_t __i__ = 0; __i__ < size; __i__++)       \
    buf[__i__] = value;


But got some with const char* 

This will still need to work because of other packages, including with bool
(used in the tisean and control package). But we should deprecate and replace
with standard C++ features that do it for us.




    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?48793>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

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