Giter Club home page Giter Club logo

learn_note's Introduction

learn_note

学习笔记、面试复习、涵盖C++,Python,Cuda,深度学习模型压缩等,详细内容不间断更新。

C++ 核心学习

智能指针

普通指针的问题

  • 资源泄露
int main()
{
    int *p=new int;
    *p=1;
    p=new int;//错误,之前的内存已经泄露
    delete p;
    return 0;
}
  • 迷途指针
int main()
{
    int *p1=new int;
    int *p2=p1;
    delete p1;
    *p2=1;//错误,p2指向的内存已经被释放
    return 0;
}
  • 野指针
int main()
{
    int *p;
    *p=1; //错误,未初始化,野指针
    return 0;
}

解决办法:智能指针

  1. shared_ptr:C++11共享所有权
  2. unique_ptr:C++11独占权
  3. auto_ptr:C++中已废弃

共享指针shared_ptr特性

  1. 具有共享所有权予以
  2. 每当shared_ptr的最后一个所有者被销毁时,关联对象都将被删除(或关联资源被清楚);

创建方式

方式一:

shared_ptr<string> p{new string("tom")};

方式二:

shared_ptr<string> p;
p.reset(new string ("tom"));

方式三:

shared_ptr<string> p=make_shared<string>("tom");

推荐方式三:更快 一次复制,更安全。

使用

shared_ptr<string> p1=make_shared<string>("tom");
shared_ptr<string> p2=make_shared<string>("jerry");

(*p1)[0]='T';
p2->replace(0,1,"i");

vector<shared_ptr<string>> vt;
vt.push_back(p1);
vt.push_back(p2);
vt.push_back(p1);

//vt 内容为 tom jerry tom

*p1="tomy";
//vt 内容为 tomy jerry tomy
  • *p1,解引用
  • p2->repalce 解引用,并调用成员函数
  • 向容器插入p1,只是增加一次引用

引用计数法

cuda

Python

CPython

numba

深度学习模型压缩

learn_note's People

Contributors

y132om avatar

Watchers

 avatar

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.