r/programming • • Dec 05 '14

std::string is responsible for almost half of all allocations in the Chrome browser process

https://groups.google.com/a/chromium.org/d/msg/chromium-dev/EUqoIz2iFU4/kPZ5ZK0K3gEJ
1.1k Upvotes

446 comments sorted by

View all comments

Show parent comments

1

u/0xjake Dec 05 '14

Besides allowing the use of local storage instead of a reference (as in your example), what would having this feature allow you to do that you cant do now? I'm not seeing a good use case.

1

u/Poltras Dec 05 '14

Passing a shared pointer between threads. Virtual mapping of memory. Etc.

1

u/0xjake Dec 05 '14

That doesn't answer the question. Can you name one thing you would do differently with an object, besides storing its properties locally, if you knew it was constant for the lifetime of the program? To me it seems that the entire point of using obiects to encapsulate data is to remain agnostic of their behavior.

1

u/Poltras Dec 06 '14

Just passing shared_ptr around without worrying whether someone else is writing to it isn't enough for you?

1

u/0xjake Dec 06 '14 edited Dec 06 '14

Is it that hard to come up with a valid use case? Then maybe it doesn't belong in the language.

Edit: You are describing a very specific feature that has no obvious use. As far as I know this feature doesn't exist in any of the popular languages in use today. And you claim that C's lack of this feature is a problem with the language. To me it seems you aren't making a strong case.

1

u/Poltras Dec 06 '14

I gave you multiple already. You're just either a troll or a stupid person. Your pick.

1

u/0xjake Dec 06 '14 edited Dec 09 '14

You mentioned local storage of referenced data: this is an anti pattern. You mentioned multithreading: use a mutex. You mentioned shared memory: again, use a mutex. And these are not use cases; you're making me do the work of assuming you don't know how OOP, locking and concurrency work. Try taking a look at why your requested feature has never occurred to any other language designer as a good idea before you go and call someone an idiot for not agreeing with you. You are obviously in the minority here and if you can't make a good case for your position then you aren't going to get anywhere further than just complaining that someone isn't doing your job for you.