Anton Shabouta "Implementing async binary clients in pure PHP" Fwdays
油
- Have you ever think how PDO work under the hood?
- What if tomorrow you need to write own DB driver from scratch?
- How to approach such tasks and get around the pitfalls?
- Is it possible to achieve in pure PHP performance comparable to the C extension?
In this talk I will try to answer these and other questions related to the development of clients for various binary protocols. We also analyze the nuances of the asynchronous driver implementation and dive into the world of low-level and not-so-optimizations.
9. 丕从舒亰舒亠仍亳
#include <iostream>
using namespace std;
int main() {
double a = 7.5;
cout << "a contain: " << a << endl <<
"a address is " << &a << endl;
return 0;
}
a contain: 7.5
a address is 0xbfea6ef8
10. 丕从舒亰舒亠仍亳
#include <iostream>
using namespace std;
int main() {
int N = 5;
int* a = new int[N];
for (int i = 0; i < N; i++)
cout << "a[" << i << "] = " <<
&a[i] << endl;
cout << "sizeof(int value) =
<< sizeof(N) << endl;
return 0;
}
11. 丕从舒亰舒亠仍亳
#include <iostream>
using namespace std;
int main() {
int N = 5;
int* a = new int[N];
for (int i = 0; i < N; i++)
cout << "a[" << i << "] = " << &a[i]
<< endl; cout << "sizeof(int value) =
" << sizeof(N) << endl; return 0;
}
a[0] = 0x84a6008
a[1] = 0x84a600c
a[2] = 0x84a6010
a[3] = 0x84a6014
a[4] = 0x84a6018
sizeof(int value) = 4
12. 丕从舒亰舒亠仍亳
#include <iostream>
using namespace std;
int main() {
int N = 2;
int a[N][N];
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
cout << "a[" << i << "][" << j << "]
=
<< &a[i][j] << endl;
return 0;
}
13. 丕从舒亰舒亠仍亳
#include <iostream>
using namespace std;
int main() {
int N = 2;
int a[N][N];
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
cout << "a[" << i << "][" << j << "]
=
<< &a[i][j] << endl;
return 0;
}
a[0][0] = 0xbfe4d258
a[0][1] = 0xbfe4d25c
a[1][0] = 0xbfe4d260
a[1][1] = 0xbfe4d264
14. 丕从舒亰舒亠仍亳
#include <iostream>
using namespace std;
int main() {
int d = 25;
int* a = &d;
cout << "d = " << d << " " << "&d =
<< &d << endl << "a = " << a << " *a =
<< *a << endl << "&(*a) = " << &(*a)
<< endl;
*a = 123;
cout << "d = " << d << endl << "*a =
<< *a << endl;
return 0;
}
d = 25 &d = 0xbfeff258a = 0xbfeff258 *a
= 25&(*a) = 0xbfeff258d = 123*a = 123
15. 丕从舒亰舒亠仍亳
#include <iostream>
using namespace std;
int main() {
int N = 5;
int p[N];
for (int i = 0; i < N; i++) {
p[i] = i;
cout << "p[" << i << "] = << p[i] << " ";
}
cout << endl;
for (int i = 0; i < N; i++) {
*(p+i) = (N-1) i;
cout << "p[" << i << "] = <<
p[i] << " ;
}
cout << endl;
return 0;
}