help-octave
[Top][All Lists]
Advanced

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

Re: Casting from an Octave int value to a pointer.


From: Pantxo
Subject: Re: Casting from an Octave int value to a pointer.
Date: Thu, 23 Jan 2014 03:23:36 -0800 (PST)

mpender wrote
> I reviewed the earlier thread, but I want to have more than one pointer,
> so assigning the value to a global static variable doesn't really address
> the need.  In the longer term I actually plan to use a structure to
> contain more information about the reserved space (e.g. type:
> bool/int/float, # rows, # columns, pointer address), but this is just an
> intermediate step and making the code childproof is not a primary concern
> at the moment.  Also, since I plan to eventually reserve the memory on a
> CUDA device and not in the main memory of the host computer I am not sure
> I can trust the operating system to release any memory allocated with
> malloc when the program ends, especially if it ends prematurely.
> 
> I am not sure I understand how to go about deriving an octave_base_value
> class so the oct file can return a proper octave object containing the
> pointer, but that seems like a better approach.  I would like to see the
> cast strategy used before to manage the operation, but I think I see the
> issue regarding testing whether the pointer is an unsigned 32 bit or
> unsigned 64 bit integer.  What I don't know is how to deal with that at
> compile time?
> 
> Ultimately, much of this would really be necessary if I could figure out
> how to modify the contents of a global array from an oct file.  I found
> the example of modifying a global scalar, but it does not seem to work the
> same way for an array variable.
> 
> Thanks, Mike

To store more than one pointer you can use a std::vector or map as I did. 
In order to determine the architecture at compile time, I think I used to
test __SIZEOF_POINTER__ (gcc > 4.2 only) in a macro (following [1]).
Now about deriving octave_base_value, there are many examples on how to do
so in octave forge packages (see e.g instrument-control sources). You may be
also interested by this thread [2].

[1]
http://stackoverflow.com/questions/1288189/elegant-and-safe-way-to-determine-if-architecture-is-32bit-or-64bit
[2]
http://octave.1599824.n4.nabble.com/document-how-to-derive-octave-value-class-tc4661019.html



--
View this message in context: 
http://octave.1599824.n4.nabble.com/Casting-from-an-Octave-int-value-to-a-pointer-tp4661233p4661306.html
Sent from the Octave - General mailing list archive at Nabble.com.


reply via email to

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