Skip to content

Instantly share code, notes, and snippets.

@YuehChuan
Created April 27, 2020 14:27
Show Gist options
  • Save YuehChuan/ab7cdeb8cebf53f6afc9579cda1e924e to your computer and use it in GitHub Desktop.
Save YuehChuan/ab7cdeb8cebf53f6afc9579cda1e924e to your computer and use it in GitHub Desktop.
(parameter with reference or pointer)g++ -std=c++11 main.cpp -o main
#include <iostream>
#include <memory>
void foo( const std::shared_ptr<int> p)
{
static int x = 0;
*p = ++x;
// printf("address p %p \n",p);
// printf("value x %d \n",x );
// printf("value p %d \n",*p);
}
int main()
{
auto p = std::make_shared<int>();
auto start = clock();
for (int i = 0; i < 10; ++i)
{
foo(p);
}
std::cout << "Took " << clock() - start << " ms" << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment