delete symbol vs setting symbol to nil

Q&A's, tips, howto's
Locked
HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

delete symbol vs setting symbol to nil

Post 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
Hans-Peter

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Re: delete symbol vs setting symbol to nil

Post 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
Hans-Peter

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: delete symbol vs setting symbol to nil

Post 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.

Locked