Skip to content

Instantly share code, notes, and snippets.

View alchem0x2A's full-sized avatar
👨‍🍼

T.Tian alchem0x2A

👨‍🍼
View GitHub Profile
@alchem0x2A
alchem0x2A / memcpy_simple.cpp
Created April 20, 2018 16:07
Memory copy of pointers in c++
#include <iostream>
#include <cstring> //memcpy implemented here
// Copy pointer y from x
void copy_pointer(double *y, const double *x, size_t n){
// The size in memcpy is byte length!
std::memcpy(y, x, n * sizeof(double));
}
int main() {
@alchem0x2A
alchem0x2A / array_point_func.cpp
Created April 20, 2018 14:59
Right Handle of Array Point with function
#include <iostream>
// Return vector y = x * x
void manipulate(double *y, double *x, size_t n){
/* x and y must be initialized! */
std::cout << "Inside the function" << std::endl;
std::cout << "Size of x?: " <<
sizeof(x) << " "
<< "Size of y?: "
<<sizeof(y)
@alchem0x2A
alchem0x2A / rand_array_generate.cpp
Created April 17, 2018 16:37
[c++] Fill an array with lambda function
#include <algorithm>
#include <iostream>
#include <random>
int main() {
std::mt19937_64 gen(42);
std::uniform_real_distribution<double> uni(-10.0, 10.0);
double *numbers = new double[20];
/*use std::generate to fill the array pointer with lambda function*/
std::generate(numbers, &numbers[20],
@alchem0x2A
alchem0x2A / mt19937.cpp
Created April 17, 2018 16:23
[C++] mt19937 snippet
#include <random>
#include <iostream>
int main()
{
std::random_device device;
/* Or use any number replace the device() */
std::mt19937 generator(device());
std::uniform_int_distribution<int> distribution(1,6);