Comparing String with Symbol

  • Thread starter Iñaki Baz Castillo
  • Start date
I

Iñaki Baz Castillo

SGksIGxvc3RzIG9mIFJ1YnkgbWV0aG9kcyBhbGxvdyBTdHJpbmcgb3IgU3ltYm9sIGFzIHBhcmFt
ZXRlciwgZm9yIGV4YW1wbGU6CgpbIkFBQSIsIkJCQiJdLnNlbmQoJ2ZpcnN0JykKPT4gIkFBQSIK
ClsiQUFBIiwiQkJCIl0uc2VuZCg6Zmlyc3QpCj0+ICJBQUEiCgpJZiBJIHdhbnQgdG8gYWNjZXNw
dCBTdHJpbmcgb3IgU3ltYm9sLCBpcyB0aGVyZSBhbiBlYXN5IHdhdCB0byBhbGxvdwpib3RoIHdp
dGhvdXQgZG9pbmcgc29tZXRoaW5nIGV4cGxpY2l0IGFzOgogIGlmIHBvcyA9PSA6Zmlyc3QgfHwg
cG9zID09ICdmaXJzdCcKCk1heWJlIHVzaW5nOgogIGlmIHBvcy50b19zID09ICdmaXJzdCcKaXMg
dGhlIGJlc3Qgd2F5PwoKLS0gCknDsWFraSBCYXogQ2FzdGlsbG8KPGliY0BhbGlheC5uZXQ+Cg==
 
R

Roger Pack

I'd rather use to_sym instead of to_s.

matz.

I'd use either one except that [quoting Tim Harper]

once a symbol is allocated, it is never garbage collected.

This opens up a potential DOS attack: if you convert any user input to
symbols (via #to_sym or #intern), they could easily fill your symbol
space up and eat all of the available system memory.

We'd all be wiser than I was a few minutes ago to keep this present when
deciding whether to use symbols or strings:

http://blog.hasmanythrough.com/2008/4/19/symbols-are-not-pretty-strings
--

or, in other words
loop { rand(10000000).to_sym }
# uses up memory in a hurry :)

-R
 
M

Michael Neumann

Roger said:
I'd rather use to_sym instead of to_s.

matz.

I'd use either one except that [quoting Tim Harper]

once a symbol is allocated, it is never garbage collected.

This opens up a potential DOS attack: if you convert any user input to
symbols (via #to_sym or #intern), they could easily fill your symbol
space up and eat all of the available system memory.

We'd all be wiser than I was a few minutes ago to keep this present when
deciding whether to use symbols or strings:

http://blog.hasmanythrough.com/2008/4/19/symbols-are-not-pretty-strings
--

or, in other words
loop { rand(10000000).to_sym }
# uses up memory in a hurry :)

This one isn't better, despite being shorter ;-)

a = []; loop { a << 1 }

Or in general, "loop { }" is not a very good idea...

Couldn't resist ;-)

Regards,

Michael
 
S

Simon Krahnke

* Michael Neumann said:
Albert said:
Michael said:
# uses up memory in a hurry :)
This one isn't better, despite being shorter ;-)

a = []; loop { a << 1 }

A slight improvement is to change '1' to '1.0'. A Fixnum doesn't
allocate an object structure.

Yes, but it will run out space regardless :)

No, that depends on how much space is available.

mfg, simon .... l
 
P

Phillip Gawlowski

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Simon Krahnke wrote:
|
|> Albert Schlef wrote:
|>> Michael Neumann wrote:
|>>>> # uses up memory in a hurry :)
|>>> This one isn't better, despite being shorter ;-)
|>>>
|>>> a = []; loop { a << 1 }
|>> A slight improvement is to change '1' to '1.0'. A Fixnum doesn't
|>> allocate an object structure.
|> Yes, but it will run out space regardless :)
|
| No, that depends on how much space is available.

Space is a finite resource. Sooner or later, that code *will* consume
all available memory.

- --
Phillip Gawlowski
Twitter: twitter.com/cynicalryan
Blog: http://justarubyist.blogspot.com

~ - You know you've been hacking too long when...
...you find out that you can't get to sleep, because you are, in fact,
the program you're designing, and can't run to completion as the lower
level routines haven't been coded yet. [This may be one of the
disadvantages of top-down design...]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkgjQ5EACgkQbtAgaoJTgL9KNACeO8LQ898C8c6mMFknW74JYkTQ
baYAoIjNS41z1+DU4Ap6gKRm8hwFjU4f
=GLfM
-----END PGP SIGNATURE-----
 
I

Iñaki Baz Castillo

El Jueves, 8 de Mayo de 2008, Roger Pack escribi=C3=B3:
I'd rather use to_sym instead of to_s.

matz.

I'd use either one except that [quoting Tim Harper]

once a symbol is allocated, it is never garbage collected.

This opens up a potential DOS attack: if you convert any user input to
symbols (via #to_sym or #intern), they could easily fill your symbol
space up and eat all of the available system memory.

We'd all be wiser than I was a few minutes ago to keep this present when
deciding whether to use symbols or strings:

http://blog.hasmanythrough.com/2008/4/19/symbols-are-not-pretty-strings

Thanks a lot for that explanation. Finally I'll use only symbols and force=
=20
method arguments to be symbols.
Parameters will only be created via coding andnot via HTTP request and so.

Thanks a lot.


=2D-=20
I=C3=B1aki Baz Castillo
 
R

Robert Dober

-----BEGIN PGP SIGNED MESSAGE-----
Space is a finite resource. Sooner or later, that code *will* consume
all available memory.
Although recent research seems to agree with you this seems to be a
bold statement nevertheless ;)
or do you mean memory, sorry could not resist.
Cheers
Robert
 
E

Evan David Light

In the PragProg Advanced Ruby Studio today, we were discussing
profiling tools with Chad Fowler and Dave Thomas. Neither are aware
of memory profiling tools for Ruby. Are there any mature memory
profiling tools out there already? A quick google search turns up
some old hits or small profiling apps.

Specifically, I was wondering about graphical memory profiling
tools. GraphViz seems an obvious approach.

Thanks,
Evan
 
R

Roger Pack

Specifically, I was wondering about graphical memory profiling
tools. GraphViz seems an obvious approach.

bleak house, ruby-prof has a memory extension and allows for
kcachegrind.
There's also a professional one out there that works in windows.

-R
 
M

M. Edward (Ed) Borasky

Evan said:
In the PragProg Advanced Ruby Studio today, we were discussing
profiling tools with Chad Fowler and Dave Thomas. Neither are aware of
memory profiling tools for Ruby. Are there any mature memory profiling
tools out there already? A quick google search turns up some old hits
or small profiling apps.

Specifically, I was wondering about graphical memory profiling
tools. GraphViz seems an obvious approach.

Thanks,
Evan

What do you mean by "memory profiling?"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,204
Messages
2,571,062
Members
47,669
Latest member
johnmaxwell

Latest Threads

Top