Page 1 of 1

delete symbol vs setting symbol to nil

Posted: Mon Aug 06, 2012 9:24 am
by HPW
Hello,

I have a question about differences between deleting a symbol vs setting a symbol to nil.
When I do some housekeeping myself and want to get a unused symbol out of the (symbols) list,
I use (delete 'symbolname) to delete the content and the symbol itself.

What the difference between them in memory usage?
Is deleting and recreating a symbol the same performance as nil it an reused it later?

Regards

Hans-Peter

Re: delete symbol vs setting symbol to nil

Posted: Mon Aug 06, 2012 9:33 am
by HPW
Ok, making this little benchmark:
> (time(dotimes (zCount 10000)(set(sym(string "TEST" zCount))10)))
140.625
> (time(dotimes (zCount 10000)(set(sym(string "TEST" zCount))10)(set(sym(string "TEST" zCount))nil)))
218.75
> (time(dotimes (zCount 10000)(set(sym(string "TEST" zCount))10)(delete(sym(string "TEST" zCount)))))
1046.875
Deleting the symbol seems to need more performance. But memory?

Hans-Peter

Re: delete symbol vs setting symbol to nil

Posted: Mon Aug 06, 2012 3:28 pm
by Lutz
Deleting a symbol affects the symbol-tree and a check for reference from resident code or data is made. The memory usage of a symbol is very little with 28 bytes plus the name string on 32bit newLISP on Windows.