#include <cstdio>
#include <cstdlib>
#include <map>
std::map<void*, size_t> BLOCKS;
void* operator new(std::size_t sz) {
std::printf("global op new called, size = %zu\n",sz);
void* p = std::malloc(sz);
//if(p) BLOCKS[p] = sz;
return p;
}
void operator delete(void* ptr) noexcept
{
std::puts("global op delete called");
std::free(ptr);
}
int main() {
int* p1 = new int;
delete p1;
}
extern "C" __declspec(dllexport) int* CallNewProccess()
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
if(!CreateProcess(NULL, const_cast<WCHAR*>(L"cmd"), NULL, NULL,
FALSE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi))
{
printf( "CreateProcess failed (%d).\n", GetLastError() );
return 0;
}
return pi.hProcess;
}
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
class WinApiClass
{
[DllImport("DLL4.dll")]
[DllImport("kernel32.dll", SetLastError=true)]
static extern bool CloseHandle(IntPtr hObject);
public static extern IntPtr CallNewProccess();
}
static void Main(string[] args)
{
IntPtr hndl = 0;
try
{
hndl = WinApiClass.CallNewProccess();
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
if( hndl != 0 )
{
CloseHandle(hndl);
}
Console.WriteLine("Press any key to continue...");
Console.ReadKey(true);
}
int main()
{
//...
thread first (...);
first.join();
return 0;
}
#include <linux/timer.h>
timer_setup(ptimer, pfunc, (u32)cntx);
ptimer->function = pfunc;
ptimer->data = (unsigned long)cntx;
init_timer(ptimer);
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
const double percent = 5.023;
long double fn(const long double &one,const long double &two)
{
return ((one + two) / 100) * percent;
}
int main()
{
vector<long double> v;
for(int i=0;i<=10000;++i)
{
v.push_back(i);
}
sort(v.begin(),v.end());
partial_sum(v.begin(), v.end(), v.begin(),fn);
long double sum = std::accumulate(v.begin(), v.end(), 0);
cout<<sum<<endl; //2.63956e+06
return 0;
}
#include <iostream>
#include <numeric>
#include <set>
#include <algorithm>
#include <iterator>
using namespace std;
const double percent = 5.023;
typedef long double ddouble;
typedef multiset<ddouble> DblSet;
int main() {
int size = 10;
ddouble *d = new ddouble[size];
for(int i=0;i<size;++i)
{
d[i]=i;
}
DblSet myset(d,d+size);
ostream_iterator<ddouble> output( cout, " ");
while(myset.size()!=1)
{
ddouble a = *myset.begin();
myset.erase(myset.begin());
ddouble b = *myset.begin();
myset.erase(myset.begin());
myset.insert(myset.begin(),((a+b)/100)*percent);
}
copy(myset.begin(),myset.end(),output);
delete d;
return 0;
}