Comments (4)
@sunqinzheng 不 delete 会内存泄露吧。 你的实现 https://github.com/ds-sww/codebase/pull/109/files 似乎没有析构?
为了避免这个野指针的错误,应该必须要实现复制构造和赋值构造,在里面对指针的内容做一遍拷贝。
这样这个类就是一个value-like的。 我的实现包括一些同学的实现都没考虑。
from codebase.
。。。貌似看错了
只是一眼看到delete没赋值有些洁癖。。。
from codebase.
@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.
shared_ptr 大法好。
from codebase.
Related Issues (18)
- TA说(抛砖引玉) HOT 2
- 为什么需要测试
- Github教育福利
- 为什么不用引用 HOT 3
- assignment1&3 HOT 1
- _(:з」∠)_ 为什么不需要用到fetch HOT 1
- First Issue HOT 1
- Share HOT 1
- 关于BM算法的一点问题 HOT 1
- Assignment4 值得关注的提交
- Assignment 1 issue HOT 3
- eric's pull requests HOT 1
- Assignment1 TA's solution
- 与课程仓库同步 HOT 2
- 不用自己释放指针,是不是可以这样? HOT 4
- Assignment 2 题目 HOT 3
- pull request 被close掉同学注意。Git Branch 的使用[重要]
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from codebase.