Skip to content

Instantly share code, notes, and snippets.

@wjx0912
Last active March 24, 2018 07:38
Show Gist options
  • Save wjx0912/cff38e4b6c90a29c8daaab9fe63f374b to your computer and use it in GitHub Desktop.
Save wjx0912/cff38e4b6c90a29c8daaab9fe63f374b to your computer and use it in GitHub Desktop.
c++ auto delete(malloc, new...)
char *buffer = (char *)malloc(len);
std::shared_ptr<void> _free_ptr((void *)buffer, [](void *p){
free(p);
});
// 补充
// FILE *fp = fopen("filepath", "rw");
// use shared_ptr deleter do fclose(fp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment