Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Pointers in Stata and the .new built-in


From   "Sergiy Radyakin" <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: Pointers in Stata and the .new built-in
Date   Mon, 3 Dec 2007 11:46:03 -0500

Hello All!

I am using pointers in Stata, and facing a problem allocating memory
for my new variables.

*** -------------------------------------------------------

class myclass {
  double x
  string next
}

.p=.myclass.new
di "`.p.objkey'"

.p=.myclass.new
di "`.p.objkey'"

*** -------------------------------------------------------

Both times I see the same memory address (a "key" in Stata's language).

I would expect that Stata will follow the other languages, and
allocate memory for an instance of myclass, assign the address to p,
then allocate another chunk of memory and assign it to p (older
reference must be lost, but the memory chunk allocated in the first
statement must remain allocated to the program). Yes, I know that I
will have to make sure that I release all the chunks after my program
completes to prevent memory leaks. But how do I allocate them in the
first place?

A second question is: is there any dedicated pointer type in Stata? I
currently declare pointers as strings (see above example).


Thank you,
    Sergiy Radyakin
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index