03 2017 档案

operator new 和 new operator
摘要:operator new 的功能很简单, 就是分配一块连续的内存。 当我们写下::operator new时, 调用的实际上就是全局的operator new。 new operator 的功能就会复杂一些。 如果内存分配失败, 上述代码并不会返回一个空指针, 而是会抛出一个异常。 当我们写下上述代 阅读全文

posted @ 2017-03-27 11:25 yohaha 阅读(147) 评论(0) 推荐(0)

hdu 1007 Quoit Design 分治求最近点对
摘要:#include using namespace std; pair a[100005], tmp[100005]; double ans; double getDis(const pair& lhs, const pair& rhs) { return (lhs.first-rhs.first)*(lhs.first-rhs.first) + (lhs.second-rhs.se... 阅读全文

posted @ 2017-03-18 12:48 yohaha 阅读(134) 评论(0) 推荐(0)

实现一个简单的shared_ptr
摘要:template class shared_ptr { public: explicit shared_ptr (T *ptr): mPtr(ptr), cnt(new int(1)){} shared_ptr(const shared_ptr& rhs): mPtr(rhs.mPtr), cnt(rhs.cnt){ ++*cnt; } shared_ptr& oper... 阅读全文

posted @ 2017-03-17 17:09 yohaha 阅读(161) 评论(0) 推荐(0)

导航