[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Casting from an Octave int value to a pointer.
From: |
mpender |
Subject: |
Re: Casting from an Octave int value to a pointer. |
Date: |
Wed, 22 Jan 2014 16:44:22 -0800 (PST) |
Pantxo wrote
> I have used the same strategy to return pointer address to the interpreter
> in the past (see this thread [1]), but I was advised not to do so as the
> user may change the value of the address and the free operation would lead
> to unintended results.
>
> Basically, I was advised to either store the pointer into a global static
> variable inside my oct file (all DEFUN that need the pointer must be
> defined in the same oct file in order to have access to the static
> variable), or derive octave_base_value class so that the oct file can
> return a proper octave object containing whatever pointer you like.
>
> If you really want to use the cast strategy I can search in my old files
> the way I managed the operation. AFAIR the main issue was to test whether
> I was on a 32 or 64 bit : sizeof(pointer) depends on the architecture but
> not sizeof(int).
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
--
View this message in context:
http://octave.1599824.n4.nabble.com/Casting-from-an-Octave-int-value-to-a-pointer-tp4661233p4661289.html
Sent from the Octave - General mailing list archive at Nabble.com.