Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> You can see in my example that non-lexically scoped resources are involved also.

Please explain your example further then, because I don't see it.

> Secondly, doing RAII into and out of a map container is largely a poor idea, and C++ programmers expend energy fighting it.

Again, explain, please. Why is it a "poor idea"? Any links, at least? "Fighting it"... how, exactly?

(It's been a while since I was a professional C++ programmer, but I don't really recognize this characterization.)

> The assignment operation and constructors and destructors of the map element all have lexical scopes somewhere.

Well, yes, but what about the MAP itself? It could easily be heap allocated.

I'm sorry, I just don't see what you're on about.



The map being heap allocated somewhere means this, in its most basic form:

  {
    map<whatever> *ptr = new map<whatever> ;

    // forgotten delete
  }
If you don't want the heap allocated map to leak, and you want that management to be automated, you need some smart pointer type to reference it; map itself doesn't help.

All RAII-driven management of heap resources is tied to some scope somewhere. Anything not tied to scoping has to be treated explicitly: try to calculate the lifetime and explicitly dispose of the resource.


AFAICT you're saying that RAII = RC. Am I correct in thinking that?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: