Giter Club home page Giter Club logo

Comments (4)

whimsycwd avatar whimsycwd commented on July 27, 2024

@sunqinzheng 不 delete 会内存泄露吧。 你的实现 https://github.com/ds-sww/codebase/pull/109/files 似乎没有析构?

为了避免这个野指针的错误,应该必须要实现复制构造和赋值构造,在里面对指针的内容做一遍拷贝。
这样这个类就是一个value-like的。 我的实现包括一些同学的实现都没考虑。

from codebase.

sunqinzheng avatar sunqinzheng commented on July 27, 2024

。。。貌似看错了
只是一眼看到delete没赋值有些洁癖。。。

from codebase.

whimsycwd avatar whimsycwd commented on July 27, 2024

@DogeDogeDogeDogeDogeAAAAAAAAAAAAAAAAAAA 不是自动deep-copy, 必须自己实现clone. 默认行为所有对象都不深度拷贝,只拷贝引用。 但是因为由gc来回收。不像C++要手动回收,就不会有内存泄露,或者是作用域的问题。

update1:
从写Java的角度来看, 两个不同array访问同数据是最正常和自然了,很少需要动用deep copy。

很多类库,比如Guava甚至将一些对象设计成lazy,array, arrayView
arrayView.get(i) {
dosometingWith(array[i]);
}
一堆View。观察同一数据。

update2:
语言影响思考方式 , 这个我学python和最近切换到C++, 还有看函数式编程等等, 都有强烈的感觉。

这几天看STL,看Generic Programming, 看到STL之父Alexander 对OO的观点。

I find OOP technically unsound. It attempts to decompose the world in terms of interfaces that vary on a 
single type. To deal with the real problems you need multisorted algebras - families of interfaces that span
 multiple types. I find OOP philosophically unsound. It claims that everything is an object. Even if it is true 
it is not very interesting - saying that everything is an object is saying nothing at all. I find OOP 
methodologically wrong. It starts with classes. It is as if mathematicians would start with axioms. You do 
not start with axioms - you start with proofs. Only when you have found a bunch of related proofs, can you
 come up with axioms. You end with axioms. The same thing is true in programming: you have to start 
with interesting algorithms. Only when you understand them well, can you come up with an interface that
 will let them work."

from codebase.

foreverbell avatar foreverbell commented on July 27, 2024

shared_ptr 大法好。

from codebase.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.