Вы находитесь на странице: 1из 131

-

-
2012 .
1


..........................................................................................................................................................................
1.

........................................................
........................................................................................................................................5
...................................................................................................................6
AGILE ......................................................................................................................................12
.................................................................................................17
...................................................................................................26

2.

...........................................................................................................
SAFE PROGRAMMING.......................................................................................................................................27
SECURE PROGRAMMING...................................................................................................................................39
...................................................................................................50

3.

.......................................................
..................................................................................................................................52
.........................................................................................53
...........................................................................................................................59
-.........................................................................................................69
-..........................................................................................71
..........................................................................................................75
...................................................................................................85

4.

............................................................................................................................................................
1. 1.........................................................................87
2. 2.........................................................................88
3. , 2.................90
4. 3.......................................................................100
5. , 3...............102
SENDER..........................................................................................................................................................102
RECIEVER.......................................................................................................................................................109
6. AGILE- ......................................127
7. AGILE- ......................................128
8. ...............................................129

()
,


, .

,
, ,

.

:
:
: ,
,
,

;
:
, ,
.
:
: ,
, ;
:

,
,
;
:
C C++
.

:


,
;


,
, ;
3


(
);

, ,
;

,
,
;

.
17 , 34
, 129 .
:
;
;
.
.
,

.

,
.

.
.
,
.

1.


, ,
.
:
- ,
,
;


,
, ,
, ;

(, , ),
, , ,
, , .
/ ;
,
,
, ,

(
, , .);
, ,
, ;


(, ),
( , ,
, .),
(,
),
(, , );
(, , ,
, );

,
;

,
.
5

, ,
, ,
(. ).

,
, Agile (. ) RUP [1].
:
1.
? .
2. .

,
,
,
, , , .

( 1).
1970 .. ,
[17], ,
.

:


(, )

( )


,
.

1.
.
,
.
,
, ,

.
,
.
,
.
.
, .

.
, ,

7

, , ,
.

,
, ( )
.

,
.

, ,
.

.
, ,
( 2). ,
, RUP (Rational Unified Process) [1].

:
,
;

,
;

;
;
,
;
;
;
;
.

2.
.

,
.
1988 .
,
.
, ,
, .
, .
4 :
;
;
;
9

.

, 4 (. 3):
;
;
;
.

3.
.
, .
, : Spiral Architecture
Driven Development [6].

, .
:
;
;
;
10


;
, ;
;
,
;
,
;
;

.
,
,
.
V- ,
V,
[7]. V
, ,

.

4. V- .

11

V- 1980-
:
V-
.
,
.
V-
,
,
.
V-Model ,
.
PRINCE2 ,
.
,
,
, ,
, .

,
, ,
, ,
V, .
:
1.
? .
2.
- ?
.
Agile
, Agile- (. Agile software
development) ,

,
,
.
Agile , Agile
Manifesto ( 11-13 2001 ,
Extreme programming, Scrum, DSDM, Adaptive
software development, Crystal Clear, Feature-driven development, Pragmatic
12

Programming) [8]. Agile Manifesto 4 (. ) 12


(. 7).
Agile-:
, ;
,
;
, ;
, .
Agile-:

;
(
);
(
);
,
;
,
, ;

( );

;
,
;

;
;
,
;
.
() Agile , ,
: , ,
, , .
.
Agile
, , ,
,
,

, .
13

Scrum () ,
,
, ( . sprints),
,
( 5).
1986 : ,
, - ,
. , ..
. scrum , .
1990- .

5. Scrum-.
-:
-
o - (. Scrum Master) ,
,
, .
o (. Product Owner)

.
o - (. Scrum Team) -
: , ,
, . .
72 .
, ,

o (. Users)
o , (. Stakeholders) ,
, .
14

o (. Managers) ,
.
o - (. Consulting Experts)
Scrum ,
2 4 .
(. Product backlog)
, ,
, .
(. Sprint backlog)
,
.
.
,
,
.
. ,
( .).
(. Burndown chart)
, ,
.

6. burndown chart.
(. Daily Scrum meeting)
( 15 ) ,
.
15

, .
:
?
?
?
-,
,
.
,
-, (.
Scrum of Scrums). -
, .
, -
:

?

,
?
- ?

(. Sprint review meeting),
.
, (. Retrospective
eeting),
, :
?
?
, :
, .
Scrum
, [3].
, Agile .
,
7 ,
. Agile
, , .
(-) :
,
.
Agile
,
.
16

, Agile
, ,
.
Agile- . , Agile-
:
,
.
-, , Agile

,
,
, .
:
1. ,

? .
2. ,
Windows?
.



.
, , ,
.
, 1987 Software Engineering Institute (SEI),
. 1991
, Capability Maturity Model for Software (CMM), 1992
,
200 ,
, CMMI (CMM Integration) [9].
CMMI ()
,

.
CMMI CMMI for Development (CMMI-DEV,
. CMMI ) ,
, ,
.
17

CMMI
( 7).

7. CMMI.
, ,
,
.
, , ,
, , ,
.
, , ,
, ,
.
, ,

.
,
.
, , ,
.

,
. .
, , ,
,

18


.
CMMI ,
.
.
,
:
;
;
;
;
;
.
,
:
;
;
;
;
;
.
,
:
;
;
;
;
.

:
;
;
;
;
.

CMMI: ,

CMMI.
(
8).
19

8. CMMI.
20


CMMI.
2 :

,
, ,
,
, ,
.. ,
, .. ,
,
, ..;

, ,
,
( , , ,
, ),
;

,
, ,
-
;

, ,
,
, ,
, ;

, ,
,
,
, ;

,
,
,
;
,
,
, , ,
, , .

21

3 :

,
,
,
, , ,
,

;


( , ,
),
,
;

, ,
;

, ,
( ,
, ),
;

, (

), ,
, ,
, ;

(,
,
),

,
, ,
;
,
,
(, , ),
, ,
;
,
,
, (, , ),
, ,
;
22



,
,
() ;

( , ,
),
(, ,
),
;
,

,
, ,
,
.
4 :

,
,
,
;

,
,
,

.
5 :

,
;


,
,
.
,
CMMI .
23

( ),
.

(. specific goals).
(. generic goals, GG)
. :
GG1:
GG2:
GG3:
GG4:
GG5:
- ,
.

(GG2)

(. generic practicies, GP):


GP2.1
GP2.2
GP2.3
GP2.4
GP2.5
GP2.6
GP2.7
GP2.8
GP2.9
GP2.10
(GG3)
:
GP3.1
GP3.2
(GG4)
:
GP4.1 ,
,
-
GP4.2



(GG5)
:
GP5.1 ,
-
24

GP5.2
.
CMMI: (. continuous)
(. staged).
CMMI
, (
).

(. capability level) 0 5 ( ).
( 1 5)
(. maturity level) .
( )

.
.
GG1 GG2.
GG3.
GG4 GG5
CMMI.
, , CMMI
,
, :
GP2.1
, .. ,
(, ),
(, ),
(,
), (,
) ..;
GP2.2 , ..
, ,
,
, ;
GP2.3 ,
, ;
GP2.4 , ,

,
;
GP2.5 , ,
,
;

25

GP2.6 ,
,
;
GP2.7
, ,
;
GP2.8 ,
, ;
GP2.9 , ,
,
, ;
GP2.10
, ,

;
GP3.2 ,
,
.
:
1. GP2.6

3 .
2. GP3.2

3 .
3.

CMMI?



:
;
,
, [3, 1, 17, 19];
1
[ 1];

.
26

2.


,
, :
safe programming ( )
,
;
secure
programming
(
)

, ,
.
Safe programming
safe programming C/C++.

, C .
,
.
, -
.
char str[5];
5 . ,
( ) , 5 ,
, \0.

:
char str1[5] = "";
char str2[ ] = {N? t? c? n? \0};

. char *str3; str3,
.

str3 .
.
C- , strlen()
NULL.
char input[ ] = hello;

char * output = NULL;


27

output = (char*) malloc (strlen (input) * sizeof


(char) );
if (output != NULL)
{
/* input output */
}
, ,
.
strcpy() ,
, , :
void foo (char * input)
{
char buffer [256];
if (input != NULL)
{
strcpy (buffer, input);
}
}
input , buffer,
.
strncpy()
, ,
NULL.
void foo (char * input)
{
char buffer [256];
if (input != NULL)
{
strncpy (buffer, input, sizeof (buffer) );
}
}
, - NULL
:
void foo (char * input)
{
char buffer [256];
if (input != NULL)
{
strncpy (buffer, input, sizeof (buffer) );
28

buffer [ sizeof (buffer) 1 ] = 0;


}
}

, , :
void foo (char * input)
{
char buffer [256];
if ( strlen (input) + 1 > sizeof (buffer) )
{
/* */
return -1;
}
else
{
strcpy (buffer, input);
}
}
, C++,
C-. std::string [10,
20, ].
, C/C++ .
. ,
:
int buffer[100];
buffer[100] = 100;
char buffer [MAX_PATH];
buffer[ sizeof (buffer) ] = 0;

C++, vector map. . [10, 17,
].

( ), , ,
. ,
.
;
, .
.
29

int A=0, B=0, C=0, D=0;


// ...
if ( A < B && C < D || G > 5);
{
//
D = A*C;
}
break switch
, , ,
. , a
b.
int a=0, b=100;
// a=1
switch (a)
{
case 1: b=10;
case 2: b=20;
case 3: b=30;
defaulte: b=0;
}
switch . default
,
. default
,
, . ,
b .
int a=0, b=100;
// a=4
switch (a)
{
case 1: b=10;
case 2: b=20;
case 3: b=30;
defaulte: b=0;
}
,

, .
30

int main ()
{
int a=5;
int b(2);
int result;

// = 5
// = 2
//

}
,

. :
, ,
( ,
,
);
: switch, if
..;
,
(, if
else );
,
, ,
,
.

, token
.
char* find_token (char* buffer, int length, char
token)
{
while (length && buffer [length -1] != token)
{
- - length;
}
return buffer + length 1;
}

.
,
.
, , ,
.
31

, , malloc
,
:
char * buffer = malloc (1000);
for (int x = 0; x < 1000; ++x)
{
buffer [x] = x;
}

,
.
-, ,
.
int main (int argc, const char * argv[ ])
{
if (argc > 1)
{
printf (argv[1]);
}
}
, ,
,
. , :
int main (int argc, const char * argv[ ])
{
if (argc > 1)
{
printf (%s, argv[1]);
}
}
,
, .
,
.
.

. .
32

if (A = 5) // -

{
...
}
if (5 = A) // -
{

}
if (5 == A) //
{

}

. ,
, ?
unsigned int x = 1000;
x = x * x * x;
.
, :
void * allocate_int_buffer (unsigned int num)
{
return malloc (num * sizeof (int));
}
,

.

.

.
.
,
, .
:

.
33

int my_flag;
//...
void f1 ()
{
if (3 == my_flag)
//...
}
void f2 ()
{
my_flag
}

= 44;

void f3 ()
{
flag = 45;
f2 ();
f1 ();
}
, ,
:
void f1 (my_flag)
{
if (3 == my_flag)
//...
}
void f2 (int * my_flag)
{
*my_flag = 44;
}
void f3 ()
{
int flag = 45;
f2 (&flag);
f1 (flag);
}
,

.
34

, ,
,
/ ,
.
, :

;
(
)
.

, ,
.
,
A B ,
:
class A
{
public: B b;
};
int foo (A & a)
{
a.b.coord.z = 64; //
// A B
// ..
}
,
.
, .
class A
{
private:
int x; // private
public:
void show() const; //
};
void function (const A& a) //
{
//...
}
35

x private
, show()
const, - ,
,
const.
,
static .
,

( , .).
,
, ,
.
(. default constructor), ,
.
,
.
.
- ,

.
, .
, ,

.
,
~ .
, , , , ..
,
, ,
.
,
.

.
,
.
delete ,
.
class A
36

{
public:
int a;
virtual ~A()
{
//...
}
};
class B : public A
{
public: int b;
};
//...
A * base_ptr = new B;
//...
delete base_ptr;
A ,
A,
B.

,
, : inet_ntoa(), localtime(), ctime()
..
, localtime() ,
.
, localtime() ,
.
.
,
.
buffer.
char* ip2str (int ip)
{
static char buffer[256];
unsigned char* bytes = &ip;
snprintf (buffer, %d.%d.%d.%d,
bytes[0], bytes[1], bytes[2], bytes[3]);
return buffer;
}
37


: , localtime_r() .
, localtime_r() ,
- .

, ,
.
, .
thread_1_function()
{
//Mutex.lock()
memcpy (DATA, x, sizeof (DATA));
//Mutex.unlock()
}
thread_2_function()
{
//Mutex.lock()
if( DATA [msg_offset] == DMAX)
// ...
//Mutex.unlock()
}
,
.
, ,
TABLES ,
, , , .
void init_tables ( );
TABLE* get_tables ( );
TABLE* free_tables ( );
void print_tables (TABLE * tables)
int main()
{
TABLES tables;
tables = get_tables ( );
// , init_tables
if (tables != NULL)
{
print_tables (tables);
free_tables ( );
// ,
}
free_tables ( );
38


}
:
,
(, );

,
;
,
.
:
1. C/C++,
safe programming.
2. , ,
safe programming?
3. ,
.
4. ,
: ,
.
Secure programming
Secure programming , ..
, ,
, ,
. .
,
, ,
.

- .
,
,
, .
,
, ,
.
, , ,
, ,
.
39

, ,
.
, ,
, ,
, , SQL- .
,
. , , :
, ;
;

, .
:

;
( ..)
;

;
, ,
.
, , ,
. ,
, SQL, ,
..

,
.
, :
;
;
;
;
, ;
.
:
;
;
.
.
.
.
[11]:
40

, , , ..
,
(), , ,
,
(PIN). ,
;
, , ,
, , , , . ,
;
, ,
, , ,
, , , .
,
, .

. ,
( )
,
.

.
,
.

,
.

. ,

,
.
, ,
,
.
-
( - ) (,
). (
).
.

41


,
.
.
,

,
, .
,
.
Shell-
(,
).
Shell ,

.

,
.

, . ..
, ,

.
shell- ,
,
.
(, )
-,
, .
,
.
SQL- SQL
, - , SQL
.
(,
, , ),
/
.
,
( ) .
42

, , ,
SQL- ,
. , PHP-
# ...
$id = $_REQUEST['id'];
$res = mysql_query("SELECT * FROM people WHERE p_id
= $id");
# ...
id, 123, SQL:
SELECT * FROM people WHERE p_id = 123
id
123 OR 1=1
:
SELECT * FROM news WHERE id_news = 123 OR 1=1
id
2;SHUTDOWN.
,
SQL SQL-
( people
p_id ).
, .
,
.
,
, , ..
.. , SQL ,
, . ,
.

.
- (. CSRF, XSRF ross Site Request Forgery,
)
.

(, ),
43

(,
). ,
, ,
.

.
HTML .
, ,
, .
,
HTML-, <script>.
<script> ,
.
HTML-.

- , ..
, .
<script> HTML-
.
. ,
, .
, ,
,
.

. :
Code Red (2001) ,
Microsoft Internet Information Serever,
;
Slammer (2003) , MS
SQL Server, 75000 10
, .

. - ,
, .
, .
,
,
, C++,
.
, , ,
. .
44


, (. denial of service,
DoS), .
,
, ..

.
.

() ( ,
) / (
),
, .
,


-.
,
.
,
,
. .
,

(-).
:
;
;
;
, ;
.
,
,
.
,
. ,
,
.
, ,
.
( )

. ,
45

. ,
.

. gcc, ,
,
,
, .


.
,
. , , .
,

,
.
.
.
, .
, ,
, .
,
,
.

:
//...
char* buff;
int length;
read(fd, &length, sizeof(length));
if (length <= 0) return;
buff = malloc (8*length):
read (fd, buff, 8*lenght);
//...
, buff,
.
, ,
.
, 8
#define .
:

46

//...
#define KEY_SIZE 8
char* buff;
int length;
read(fd, &length, sizeof(length));
if ((lenght <=0) || (length > 0x7FFFFFFF /
KEY_SIZE))
return (ERROR);
if ((buff = malloc(KEY_SIZE*length)) == NULL)
return (ERROR);
read (fd, buff, KEY_SIZE*length);
//...

, ,
.
-, ,
, .
/. ,
.

.
:
int f()
{
return f();
}
, ,
.
-,
.
, :
int f()
{
double x[1000000];
}
(8
), .

47


. printf()- ,
, . ,
,
, .
.. char * buffer;
printf(buffer);

printf(%s, buffer);
, ..
.
, . ,
buffer ,
, %d, printf()- : buffer,
, , .
, .
, ,
, :
int main (int argc, const char * argv[ ])
{
if (argc > 1)
{
printf(argv[1]);
}
}

, .. .

. ,
, , ,
:
int i;
// ...
har* buf = (char*) malloc (i*i);
i , malloc .
48


, .
,

, .
,

.
,
,
.
,
, ,
, .
:
, .
, ,
.

, , .

.
, . ,
-
,
.

,
.
,
.
, :
,
NULL-;
- , ,
fopen() fclose();
( ,
),
;

;

49

,
;
() , :
dest.x = src.x + dx;
dest.y = src.y + dx;

// , dy!


;
,
) .

.

, ,
.
.
,
,
( , , .).

.
:
1. safe programming secure
programming?
2. , .
?
3. ?
, , ,
? .
4. ?
?
? .
5. , ,
printf().
6.
(. 3, 5)
safe programming secure
programming.

50


:
;
,
, [13, 10, 10];
[10,
20, , 17, ];
2
[ . 2, .
3];

,
.

51

3.


() (. embedded system)

, , ,
.
.

, ,
, (),
, , .

, :
,

;
,

;

, ,
, ,
,
. .

:
(, .
programmable logic device, PLD) ,
,
,

,



(), ,
,

, (,
) ,
52



,
.
,
..
.
:
1. ( 10
).
2.
. .

, (. Real-Time
Operating System, RTOS) ,

, .
..

. (
) .
, , :
, .. ,

, ;
,
, ..;
, ..


,
. ,

;
, ..

,
(.
);

53

,

-,
,
(. -
);
(.
);
,
, ;
.
,
.

, .. .

, :
;
;
.
.. , ,
. ,
,
.
:
, ,
;
;
.

.
..
.

.
, (
). ,
.

54


:
.

- ,
.
,

( ). ..

,
.

. :

(, );
(,
).

(,

);

(
,
)
, ,
:
(. interrupt latency
) -

;
(. task response) -

,
;
(. context switch) -

()
().
,

;
55

(. scheduling latency) -

,
- ;
.

;
,
;
(. timer jitter) -
.
.

, [15]:
:
() ;
,
( c
);

(,
);
( );
-
.
.
,
, ,

,
.
:
,
.

(- ), ,
. :
,
.
,
, .

56

,
, . ..

.

.
,
.
(. 8).
[1].
,

.
(
9).

9. .

,
.
, ,
,
.
(
10).
57


,
.
.

BSP
(Board Support Package)

HW
(CPU, RAM, Flash)

10. .
-


.
(
11).
:
, , ,

;
,

;
,
.
58

11. - .
:
1. (,
)
? .
2. (,
)
?
.

:
( );
;
;
;
-.
.


59

(). ,
() .
, ,
.

.
,
, , ,
,
.
, ,

:

12. [15].
,
.
, (
) . ,
, ,
. ,
.
, ,
,
,
,
60

.

, .

.

, .
,
.
,
:

, ..
, ,
;

,

.

.
, , Task2
Task1,
(. 13).

13. [15].

, .
(. 14).

61

14.
[15].
,

.
.

:
(. event) , 1
,
,
.

.

,
;
c (. semaphore)
,
n . ,

, .
,
;
(. mutex) ,
,
, .
,
.,
(, ), ,
, .
,
() (. );

62

(. critical sections)
() , .. ,


. (
);
(. messages)
,
,
.
,

, ;

,
,
.
,

.

, -, ,
, , ,
.
,

. ..
,
.
,
.

.


.
,
.. (. heap):
,
, , ,
, .
,
. , ..
63

:
,
. , ..
, - ,
, ,
,
,
.
.
,
.
, ,
,
, ,
.
, ,
.
:
16b, 32b .. (. 15).
, .
:
;
, ..
.
,
, .
. ,
10b , 16b.
17b, 32b.
..
: 17b ,
.
,
, ,
.
,
, ,
.

64

15. .

, ,
.
, ,
,

. , ,
.

.
,
.
:

-,
:
(. warning), ..
,
, ;
65

, ,
,
;
,

.
[3].
, , ..
. , ,
. ..
.
,
.
,
,
(, ,
, ).
, .
:
UTC (
): UTC
,
,
. ,

.
UTC: ,
UTC,
,
.
, ,
,
.

;

, , NTP (. Network
Time Protocol,
) ,

UTC,

66

(. timers)
, .
,
, :
;
;
;
.
, ..
.
:
(
);
( );
( ).
:
,

;

, ,
,
,

.
(. Real Time Clock, RTC)
, ( ,
, .). RTC
. RTC
32768 . 215
.

. x86 Intel 82C54,
1.1931816.

, 82C54.
, (

, 86, )
:
;
;
.
67


.
2
,
,
, ,
.

. ,
.
,
,
.
,

.
, ,
,
( ).
(
).

,
,
, .
,

.
, WDT (., watch dog timer, )
, .
WDT
(. 16):
, ,
, WDT;
,
WDT ,
.
,
,

WDT,
.

68

16. .
WDT (.. ,
, )
.
:
1. -
.
2.
?
-
-
.
,

.
69

- .
, ,
.
-
(. print server).
.
, ,
( ) .
,
(.
17).

17. .
,
. .. , (
), .
- .

(. 18).

, write_ptr
, .. .
.
read_ptr .

read_ptr , .

read_ptr

.
, ,
.
, ,
, .
,
.
70


, ,
.

18. .
,
.
,
.
:
1. print server
.
2. print server
.
-
, ,
,
.
(. state machine)
, , ,

,
.
(. finite-state machine)
,
71

,
.

:
;
,
;
,
;
(
), ,
;



( ).
( )
.
,
, , ,
. ,

.

(. 19).
Init , Init/S1/S2/S3
, S1/S2/S3 , 1/2/3
.

72

19. .
.
,
.
,
, ,
.

.
(.
1).
\

Init

S1

S1

S2

S2

S2

S3

S3

S1

S2

1. .
,

- .

:
;

(, );

;

,
, ..

,
.
C/C++, ,
switch-case .
73

C++
:
class FSM
{
public:
enum State { Init, S1, S2, S3 };
enum Event { X1, X2, X3};
void postEvent(Event event)
{
switch(currentState)
{
case Init:
switch(event)
{
case X1: currentState
break;
default: ERROR();
}
case S1:
switch(event)
{
case X2: currentState
break;
default: ERROR();
}
case S2:
switch(event)
{
case X2: currentState
break;
case X3: currentState
break;
default: ERROR();
}
case S3:
switch(event)
{
case X1: currentState
break;
case X2: currentState
break;
default: ERROR();
}

= S1;

= S2;

= S2;
= S3;

= S1;
= S2;

74

}
}
private:
State CurrentState;
};
:
1. .
2.
.


,
,

.
,
.
,
.


.
[12]
.
, ,
(. 20).
,
, , ,
.
, ,

, ,
, , ,
.

75

20. .

, .
, ,
. ,
.

[12].

(
, ).
:

( );

( );
,
( );
( )
( ).
,
, .

, ,
( ). ,
76

,
.
,
, .
(.. ),
( ,
).
( ).
.
L1, L2 L3.
L1, L2.
L2 L3 ( )
.

.

,
.

.

[12].
,
,
, .
.
.

, ,
(, ).
, .
-
,
.

,
.
,
, .
, (
, ) ,
. ,
,
.
77

, , .
,
, ,
. ,
,
.

, .
,
,
.
,
, .
, .
,
.
, ,
. , ,
,
.
,
,
.
, ,
.
,

, ..
,
(, ),
, ..
, , .
(, )
(, ).
,

() . ,
.

, .. .
,

.
78


, ,
.
:
;
;
;
.
.

, ,
.

:
,
, ..


,
;
,
;
,
,
,
,

,
, . ,
for ( i = 1; i < n; i++)
{
a[i] = i;
}
:
for (i = 1; i < n - 2; i = i+3)
{
a[i] = i;
a[i + 1] = i + 1;
a[i + 2] = i + 2;
}
79


, ,
, ,
;
,
.
, ,
(. );
, , ,
.
.
,
.;


,
;
..

, :
a.b.c.d ,
abcd;
sprintf(buf, %s, ) , sprintf(buf,
);
in-line
goto,
;
switch
if;
++ , ,
(

/);
.., , , [13].
, ,
.
, ++
,
C++ ,
.
-
++ .
80


-
.
,

.


, .
[12].
:


;
, ,
,
;

,
;
,
, ,
;

;

,
,
,
;

;
;

;

, ,
;

;

81



;

;

, ,
;
,
,
..

:
,
,
;

,
.

,
, ,
.
,
.

,
.
: , .
:
.
.

.
.
,
- . ,
,
,
.

. , ,

82

. , ,
.

.
(. cache . cacher )
, ,
.
,
. .
,
.
,
.
, ( SRAM),
.
,
.
,
.
,
. - -
(. cache hit),
(. cache miss).

- .

(. hit rate),
.
, ,
, .
, .
,
. .
.
,
.

.
,
.

, .
.
.
83

, -,
, .
, ,
, .
-,
,

,
(. Data-Oriented Design, DOD) [17].
, ,
,
.

(
).
,
.

.
:
,

( ,
).

, ,
,
;
-,
,

-
, ,
.
,
, ,
.. .

, , :
,
, KAP Fortran/C-;
, ,
VAST;
84

, , V-Ray.
:
1. ,
(,
) .
?
2.
(. 3, 5)

.
?
3.

.
.


:
;
,
, [15, 15];
3
[ . 4, .
5];

,
.

85

4.

1. ..
http://www.smartyit.ru/docum/os/rtos.pdf
2. .., ., . :
.
.: , 2008. 240 .
3. ...
http://library.fentu.ru/book/iriet/62/lec/oglavlenie.html
4. . Scrum: . .: , 2011. 576 .
5. Rational Unified Process //
http://www-01.ibm.com/software/awdtools/rup/
6. Spiral Architecture Driven Development //
http://sadd.codeplex.com/
7. V-model // http://v-modell.iabg.de/
8. Agile Manifesto // http://agilemanifesto.org/
9. CMMI // http://www.sei.cmu.edu/cmmi/
10. . - ++ . .:
, .: , 2001. 464 .
11. . : .
.: , 2002. . 432.
12. AIX 5L 5.3.
IBM//
http://www.regatta.cs.msu.su/doc/usr/share/man/info/ru_RU/a_doc_lib/a
ixbman/prftungd/prftungdtfrm.htm
13. ., . C++.
101 . ., , : , 2005. 224
.
14. . ++. .: , .:
, 2011. 1136 .
15. .. : /
. . . . -: , 2004. 292 .
16. .. //
http://www.booksgid.com/operating_systems_databases/5248operacionnye-sistemy-realnogo-vremeni.html
17.Chrissis M.B., Konrad M., Shrum S. CMMI: Guidelines for Process
Integration and Product Improvement. : Addison-Wesley, 2003.
688 c.
18.Noel. Data-Oriented Design (Or Why You Might Be Shooting Yourself in
The Foot With OOP) //
http://gamesfromwithin.com/data-oriented-design
19.Schwaber K. Agile Project Management with Scrum. USA: Microsoft
Press, 2004. 192 .
20.Winston R. Managing the Development of Large Software Systems //
http://www.cs.umd.edu/class/spring2003/cmsc838p/Process/waterfall.pdf
86

1. 1.
,
.
2 3
,

.
.
,
, ,
, .

,
( ,
).

,
.
,
, RUP.
,
: ,
, .

87

2. 2.

.
,
. 10 .
,
,
:
1.
char* mm_alloc(int size) size
2.
mm_free(char* buf) buf
.


.
.

,
.
, ,
:
(, ),

( ).
,
80% ,
, , .
100000
. ,
,
.
:
16
16

: 16 , 64 , 256 , 1
, 4 , 16 .

- , , .

88

C.
, , ,
.
(Windows, Unix, Linux).
(.exe) .
.

.
,
: ,
, ,
,
.

89

3. ,
2.
MemoryManager.h
#define POOL_SIZE 10485760
#define DESCRIPTORS_COUNT_MAX POOL_SIZE/16
#include "MemoryBlock.h"
using namespace std;
class MemoryManager
{
public:
MemoryManager();
MemoryManager(const MemoryManager& orig);
~MemoryManager();
char* AllocateMemory(unsigned short size);
void FreeMemory(char* buf);
void OutputStatistics();
void Visualize();
unsigned int GetAllocatedSize()
{
return _allocatedSize;
}
void Clear();
private:
char _pool[POOL_SIZE];
MemoryBlock _descriptors[DESCRIPTORS_COUNT_MAX];
unsigned int _lastAvailable,
_allocatedSize,
_descriptorsCount;
};
Memory.Manager.cpp
#include "MemoryManager.h"
#include "MMExceptions.h"
#include <iostream>
#include <windows.h>
MemoryManager::MemoryManager()
{
_lastAvailable = 0;
90

_allocatedSize = 0;
_descriptorsCount = 0;
}
MemoryManager::MemoryManager(
const MemoryManager& orig) {}
MemoryManager::~MemoryManager() {}
char* MemoryManager::AllocateMemory
(unsigned short size)
{
char* pBlock = NULL;
if(size == 0)
throw NullSizeException();
//
// ,
//
if(_lastAvailable + size <= POOL_SIZE)
{
pBlock = &_pool[_lastAvailable];
descriptors[descriptorsCount].Pointer=pBlock;
descriptors[descriptorsCount].Size = size;
descriptors[descriptorsCount].IsAvailable=false;
lastAvailable += size;
descriptorsCount++;
}
else
//
//
for(unsigned int i = 0;
i <_descriptorsCount; i++)
if(_descriptors[i].IsAvailable &&
descriptors[i].Size == size)
{
pBlock = _descriptors[i].Pointer;
descriptors[i].IsAvailable = false;
break;
}
if(pBlock == NULL)
for(unsigned int i = 0; i <
91

descriptorsCount; i++)
if(_descriptors[i].IsAvailable && _
descriptors[i].Size > size)
{
pBlock = _descriptors[i].Pointer;
descriptors[i].IsAvailable = false;
break;
}
if(pBlock != NULL)
_allocatedSize += size;
else
throw PoolFilledException();
return pBlock;
}
void MemoryManager::FreeMemory(char* buf)
{
for(unsigned int i = 0;i< _descriptorsCount;i++)
{
if(_descriptors[i].Pointer == buf)
{
descriptors[i].IsAvailable = true;
allocatedSize -= _descriptors[i].Size;
break;
}
}
}
void MemoryManager::OutputStatistics()
{
cout << "Descriptors count: " <<descriptorsCount
<< " Allocated memory: " << allocatedSize
<< "("
<< (float)_allocatedSize / POOL_SIZE * 100
<< "%)"<< endl
<< "Marked memory: " << _lastAvailable
<< "("
<< (float)_lastAvailable / POOL_SIZE * 100
<< "%)"<< endl;
}
void MemoryManager::Visualize()
{
HANDLE hConsole;
92

hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
for(unsigned int i = 0;i <_descriptorsCount;i++)
{
// -
if(_descriptors[i].IsAvailable)
SetConsoleTextAttribute(hConsole, 32);
else // -
SetConsoleTextAttribute(hConsole, 64);
unsigned short count = descriptors[i].Size /
1024; // 1
if(count == 0 &&_descriptors[i].IsAvailable)
{
count = 1;
SetConsoleTextAttribute(hConsole, 96);
// <1 -
}
for(unsigned short j = 0; j < count; j++)
cout<<' ';
}
SetConsoleTextAttribute(hConsole, 7);
}
void MemoryManager::Clear()
{
_lastAvailable = 0;
_allocatedSize = 0;
_descriptorsCount = 0;
}
MemoryBlock.h
class MemoryBlock
{
public:
MemoryBlock();
MemoryBlock(char*, unsigned short, bool);
MemoryBlock(const MemoryBlock& orig);
~MemoryBlock();
char* Pointer;
unsigned short Size;
bool IsAvailable;
};
93

MemoryBlock.cpp
#include "MemoryBlock.h"
MemoryBlock::MemoryBlock()
{
Pointer = 0;
Size = 0;
IsAvailable = false;
}
MemoryBlock::MemoryBlock(char* pointer,unsigned
short size, bool isAvailable):
Pointer(pointer),
Size(size),
IsAvailable(isAvailable)
{
}
MemoryBlock::MemoryBlock(const MemoryBlock& orig)
{
}
MemoryBlock::~MemoryBlock()
{
Pointer = 0;
}
MMExceptions.h
class MMException
{
public:
MMException(){};
~MMException(){};
virtual char* Message(){return "Error";};
};
class NullSizeException: public MMException
{
public:
char* Message();
};
class PoolFilledException: public MMException
{
94

public:
char* Message();
};
MMExceptions.cpp
#include "MMExceptions.h"
char* NullSizeException::Message()
{
return "Size can't be null";
}
char* PoolFilledException::Message()
{
return "Allocation is impossible";
}
MMTester.cpp
#include "MemoryManager.h"
#include <iostream>
class MMTester
{
public:
MMTester();
~MMTester();
void TestRandomSizes();
void TestConstSizes();
private:
void AllocateMemory();
void AllocateMemoryRandomSize();
void FreeMemory();
void ClearResults();
void OutputFinalStatistics();
static MemoryManager _manager;
static char* _pointers[DESCRIPTORS_COUNT_MAX];
unsigned int _iterationsCount, _pointersCount;
};
MMTester.cpp
#include "MMTester.h"
#include "MMExceptions.h"
95

MMTester::MMTester()
{
}
MMTester::~MMTester()
{
}
MemoryManager MMTester::_manager;
char* MMTester::_pointers[DESCRIPTORS_COUNT_MAX];
void MMTester::AllocateMemory()
{
unsigned short constSizes[] =
{16, 64, 256, 1024, 4096, 16384};
unsigned short blockSize = constSizes[rand()%6];
pointers[_pointersCount] =
manager.AllocateMemory(blockSize);
iterationsCount++;
pointersCount++;
if(_iterationsCount % 1000 == 0)
_manager.OutputStatistics();
}
void MMTester::AllocateMemoryRandomSize()
{
unsigned short blockSize = rand() % 16368 + 16;
pointers[_pointersCount] =
manager.AllocateMemory(blockSize);
iterationsCount++;
pointersCount++;
if(_iterationsCount % 1000 == 0)
_manager.OutputStatistics();
}
void MMTester::FreeMemory()
{
unsigned int delInd = _pointersCount, counter=0;
while(_pointers[delInd] == 0 &&
counter < _pointersCount)
{
delInd = rand() % _pointersCount;
96

counter++;
}
manager.FreeMemory(_pointers[delInd]);
pointers[delInd] = 0;
iterationsCount++;
if(_iterationsCount % 10000 == 0)
_manager.OutputStatistics();
}
void MMTester::ClearResults()
{
for(unsigned int i = 0; i <
DESCRIPTORS_COUNT_MAX;i++)
pointers[i] = 0;
manager.Clear();
iterationsCount = 0;
pointersCount = 0;
}
void MMTester::OutputFinalStatistics()
{
cout << "Final statistics:" << endl
<< "Iterations count: "
<< _iterationsCount << endl;
manager.OutputStatistics();
manager.Visualize();
cout << endl;
}
void MMTester::TestRandomSizes()
{
ClearResults();
srand(10);
try
{
while(_manager.GetAllocatedSize() <
0.8 * POOL_SIZE)
AllocateMemoryRandomSize();
while(_pointersCount<DESCRIPTORS_COUNT_MAX)
{
97

AllocateMemoryRandomSize();
FreeMemory();
}
}
catch (PoolFilledException e)
{
cout << e.Message() << endl;
OutputFinalStatistics();
}
}
void MMTester::TestConstSizes()
{
ClearResults();
srand(10);
try
{
while(_manager.GetAllocatedSize() <
0.8 * POOL_SIZE)
AllocateMemory();
while(_pointersCount<DESCRIPTORS_COUNT_MAX)
{
AllocateMemory();
FreeMemory();
}
}
catch (PoolFilledException e)
{
cout << e.Message() << endl;
OutputFinalStatistics();
}
}
Main.cpp
#include "MMTester.h"
#include <iostream>
using namespace std;
int main()
{
MMTester tester;
cout << "Test with random sizes from 16b to 16Kb:"
98

<< endl;
tester.TestRandomSizes();
cout << endl << "Test with constant sizes:"
<< endl;
tester.TestConstSizes();
cout << endl << "Press any key..." << endl;
getchar();
return 0;
}

99

4. 3.

.
,
(),
.
:
(10000) ,
udp- .
udp-
tcp Localhost.
IP- udp- .
ip- udp-,

50 .
, .
(),


.
1
,
.
.

.
,
( STL
map<T>,
).
C/++ ( STL,
map).
, , , .
(Windows, Unix, Linux).
(.exe) .
.


, ,
.

100

,
: ,
, ,
,
.

101

5. ,
3.
Sender
ClientTCP.h
#include <string>
using namespace std;
class ClientTCP
{
public:
ClientTCP();
ClientTCP(int portNumber, string hostName);
ClientTCP(const ClientTCP& orig);
virtual ~ClientTCP();
void SendMessage(string message);
private:
int _socketDescriptor, _portNumber;
string _hostName;
void Connect();
void HandleError(string message);
};
ClientTCP.cpp
#include "ClientTCP.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
ClientTCP::ClientTCP()
{
_portNumber = 2121;
hostName = "localhost";
Connect();
102

}
ClientTCP::ClientTCP(int portNumber, string
hostName)
{
_portNumber = portNumber;
_hostName = hostName;
Connect();
}
ClientTCP::~ClientTCP()
{
close(_socketDescriptor);
}
void ClientTCP::HandleError(string message)
{
perror(message.c_str());
exit(0);
}
void ClientTCP::Connect()
{
sockaddr_in serverAddress;
hostent * server;
server = gethostbyname(_hostName.c_str());
if (server == NULL)
{
fprintf(stderr,"Error: no such host\n");
exit(0);
}
_socketDescriptor = socket(AF_INET, SOCK_STREAM,
0);
if (_socketDescriptor < 0)
HandleError("Error opening socket");
bzero((char *) &serverAddress,
sizeof(serverAddress));
serverAddress.sin_family = AF_INET;
bcopy((char *)server->h_addr, (char
*)&serverAddress.sin_addr.s_addr,
103

server->h_length);
serverAddress.sin_port = htons(_portNumber);
if (connect(_socketDescriptor, (struct sockaddr
*) &serverAddress,
sizeof(serverAddress)) < 0)
HandleError("Error connecting");
}
void ClientTCP::SendMessage(string message)
{
char buffer[256];
bzero(buffer,256);
if(write(_socketDescriptor, message.c_str(),
message.length()) < 0)
HandleError("Error writing to socket");
if (read(_socketDescriptor, buffer, 255) < 0)
HandleError("Error reading from socket");
}
NumberGenerator.h
#define SENDERS_COUNT 10000
#include <vector>
#include <stdlib.h>
using namespace std;
class NumberGenerator {
public:
NumberGenerator();
NumberGenerator(const NumberGenerator& orig);
virtual ~NumberGenerator();
ulong GetRandomIPAddress();
uint GetRandomPortNumber();
ulong GetIPAddress(uint index);
uint GetPortNumber(uint index);
ulong ChangeIPAddress(uint index);
uint ChangePortNumber(uint index);
private:
ulong GenerateIPAddress();
104

uint GeneratePortNumber();
bool IpExists(ulong address);
bool PortExists(uint number);
ulong _ipAddresses[SENDERS_COUNT];
uint _portnumbers[SENDERS_COUNT],
_portsCount,
_ipsCount;
};
NumberGenerator.cpp
#include "NumberGenerator.h"
#include <time.h>
NumberGenerator::NumberGenerator()
{
_ipsCount = 0;
_portsCount = 0;
for(uint i=0; i < SENDERS_COUNT; i++)
{
_ipAddresses[i] = 0;
_portnumbers[i] = 0;
}
srand(time(NULL));
for(uint i=0; i < SENDERS_COUNT; i++)
{
_ipAddresses[i] = GenerateIPAddress();
_ipsCount++;
_portnumbers[i] = GeneratePortNumber();
_portsCount++;
}
}
NumberGenerator::NumberGenerator(const
NumberGenerator& orig) {}
NumberGenerator::~NumberGenerator() {}
ulong NumberGenerator::GenerateIPAddress()
{
ulong result;
do
{
105

result = rand();
}
while(IpExists(result));
return result;
}
uint NumberGenerator::GeneratePortNumber()
{
uint result;
do
{
result = rand()%63535 + 2000;
}
while(PortExists(result));
return result;
}
ulong NumberGenerator::GetRandomIPAddress()
{
uint i = rand() % SENDERS_COUNT;
return _ipAddresses[i];
}
uint NumberGenerator::GetRandomPortNumber()
{
uint i = rand() % SENDERS_COUNT;
return _portnumbers[i];
}
bool NumberGenerator::IpExists(ulong address)
{
bool existence = false;
for(uint i=0; i<_ipsCount; i++)
{
if(_ipAddresses[i] == address)
{
existence = true;
break;
}
}
106

return existence;
}
bool NumberGenerator::PortExists(uint number)
{
bool existence = false;
for(uint i=0; i<_portsCount; i++)
{
if(_portnumbers[i] == number)
{
existence = true;
break;
}
}
return existence;
}
ulong NumberGenerator::GetIPAddress(uint index)
{
return _ipAddresses[index];
}
uint NumberGenerator::GetPortNumber(uint index)
{
return _portnumbers[index];
}
ulong NumberGenerator::ChangeIPAddress(uint index)
{
ulong newValue = GenerateIPAddress();
_ipAddresses[index] = newValue;
return newValue;
}
uint NumberGenerator::ChangePortNumber(uint index)
{
uint newValue = GeneratePortNumber();
_portnumbers[index] = newValue;
return newValue;
}

107

Main.cpp
#include <cstdlib>
#include <iostream>
#include <sstream>
#include "ClientTCP.h"
#include "NumberGenerator.h"
using namespace std;
int main()
{
ClientTCP client;
cout << "Connected to the server successfully"
<< endl;
cout << "Generating senders information...";
NumberGenerator infoGenerator;
cout << "finished" << endl;
cout << "Sending information to server...";
for(ulong i=0; i <SENDERS_COUNT;i++)
{
stringstream sstream;
sstream << infoGenerator.GetIPAddress(i) <<
' '
<<
infoGenerator.GetPortNumber(i);
client.SendMessage(sstream.str());
}
client.SendMessage("EOT");
cout << "successfully" << endl;
cout << "Sending packets:" << endl;
for(ulong i=1; i<=1000000; i++)
{
stringstream sstream;
if(i % 50 == 0)
108

{
ulong oldIp;
uint oldPort;
uint j = rand() % SENDERS_COUNT;
oldIp = infoGenerator.GetIPAddress(j);
oldPort =
infoGenerator.GetPortNumber(j);
sstream << "ch " << oldIp << ' ' <<
oldPort << ' '
<<
infoGenerator.ChangeIPAddress(j) << ' '
<<
infoGenerator.ChangePortNumber(j);
}
else
{
sstream <<
infoGenerator.GetRandomIPAddress() << ' '
<<
infoGenerator.GetRandomPortNumber();
}
client.SendMessage(sstream.str());
if(i % 10000 == 0)
cout << i << endl;
}
cout << "Finished" << endl;
return 0;
}
Reciever
ServerTCP.h
#include <string>
using namespace std;
class ServerTCP
{
public:
ServerTCP();
109

ServerTCP(int portNumber);
ServerTCP(const ServerTCP& orig);
virtual ~ServerTCP();
int Accept(string& message);
private:
int portNumber, socketDescriptor,
newSocketDescriptor;
void Start();
void HandleError(string message);
};
ServerTCP.cpp
#include "ServerTCP.h"
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
ServerTCP::ServerTCP()
{
portNumber = 2121;
Start();
}
ServerTCP::ServerTCP(int portNumber)
{
portNumber = portNumber;
Start();
}
ServerTCP::ServerTCP(const ServerTCP& orig)
{
}
ServerTCP::~ServerTCP()
{
close(_socketDescriptor);
close(_newSocketDescriptor);
}
110

void ServerTCP::HandleError(string message)


{
perror(message.c_str());
exit(1);
}
void ServerTCP::Start()
{
sockaddr_in serverAddress, clientAddress;
socklen_t clientAddrLen;
socketDescriptor=socket(AF_INET,SOCK_STREAM,0);
if (_socketDescriptor < 0)
HandleError("Error opening socket");
bzero((char *) &serverAddress,
sizeof(serverAddress));
serverAddress.sin_family = AF_INET;
serverAddress.sin_addr.s_addr = INADDR_ANY;
serverAddress.sin_port = htons(_portNumber);
if (bind(_socketDescriptor,
(struct sockaddr *) &serverAddress,
sizeof(serverAddress)) < 0)
HandleError("Error on binding");
listen(_socketDescriptor, 5);
clientAddrLen = sizeof(clientAddress);
newSocketDescriptor = accept(_socketDescriptor,
(struct sockaddr *) &clientAddress,
&clientAddrLen);
if (_newSocketDescriptor < 0)
HandleError("Error on accept");
}
int ServerTCP::Accept(string& message)
{
char buffer[256];
int count;
bzero(buffer,256);
count = read(_newSocketDescriptor,buffer,255);
if(count < 0)
111

HandleError("Error reading from socket");


if(count > 0)
{
message = string(buffer, 256);
if (write(_newSocketDescriptor, "+", 1) < 0)
HandleError("Error writing to socket");
return 0;
}
else
{
message = "";
return -1;
}
}
SendersData.h
struct SendersData
{
SendersData()
{
Number = 0;
Count = 0;
};
unsigned int Number, Count;
};
PacketInfo.h
struct PacketInfo
{
PacketInfo()
{
};
PacketInfo(unsigned long IP,unsigned int port)
{
IPAddress = IP;
PortNumber = port;
}
unsigned long IPAddress;
unsigned int PortNumber;
112

bool operator<(const PacketInfo& pi) const;


bool operator==(const PacketInfo& pi) const;
};
PacketInfo.cpp
#include "PacketInfo.h"
bool PacketInfo::operator <(const PacketInfo& pi)
const
{
if (this->IPAddress < pi.IPAddress) return true;
else if (this->IPAddress == pi.IPAddress)
return this->PortNumber < pi.PortNumber;
return false;
}
bool PacketInfo::operator ==(const PacketInfo& pi)
const
{
if(this->IPAddress == pi.IPAddress &&
this->PortNumber == pi.PortNumber)
return true;
else return false;
}
ExtendedPacketInfo.h
#include "PacketInfo.h"
struct ExtendedPacketInfo
{
ExtendedPacketInfo()
{
Count = 0;
}
ExtendedPacketInfo(PacketInfo pi,
unsigned int count)
{
Info = pi;
Count = count;
}
PacketInfo Info;
unsigned int Count;
};
113

ISendersInfoCollection.h
#pragma once
#include "PacketInfo.h"
class ISendersInfoCollection
{
public:
virtual void SaveInfo(PacketInfo sender)=0;
virtual void ChangeInfo(int index,
PacketInfo oldValue,
PacketInfo newValue)=0;
virtual int FindSender(PacketInfo sender)=0;
virtual void CountUpPacket(int index,
PacketInfo sender) = 0;
};
PINode.h
#include "ExtendedPacketInfo.h"
class PINode
{
public:
PINode(ExtendedPacketInfo);
PINode(const PINode& orig);
virtual ~PINode();
void SetNext(PINode * node)
{_
next = node;
}
void SetValue(ExtendedPacketInfo value)
{_
value = value;
}
PINode * GetNext() const;
ExtendedPacketInfo GetValue() const;
private:
ExtendedPacketInfo _value;
PINode * _next;
};
PINode.cpp
#include "PINode.h"
114

PINode::PINode(ExtendedPacketInfo pi): value(pi),


next(0)
{
}
PINode::PINode(const PINode& orig) {
}
PINode::~PINode()
{
delete _next;
next = 0;
}
PINode* PINode::GetNext() const
{
return _next;
}
ExtendedPacketInfo PINode::GetValue() const
{
return _value;
}
MyList.h
#include "PacketInfo.h"
#include "PINode.h"
class MyList
{
public:
MyList();
MyList(const MyList& orig);
virtual ~MyList();
int Find(ExtendedPacketInfo Value) const;
int GetCount() const { return _count; }
ExtendedPacketInfo GetFirst() const;
void Insert(ExtendedPacketInfo);
ExtendedPacketInfo operator[] (int) const;
private:
PINode * pHead;
int _count;
};
115

MyList.cpp
#include "MyList.h"
#include <iostream>
using namespace std;
MyList::MyList(): pHead(0), count(0)
{
}
MyList::MyList(const MyList& orig)
{
}
MyList::~MyList()
{
delete pHead;
}
ExtendedPacketInfo MyList::GetFirst() const
{
if (pHead) return pHead->GetValue();
}
ExtendedPacketInfo MyList::operator [](int offset)
const
{
PINode* pNode = pHead;
for(int i=0; i<offset; i++)
pNode = pNode->GetNext();
return pNode->GetValue();
}
int MyList::Find(ExtendedPacketInfo Value) const
{
PINode * pNode = 0;
int Position;
for(pNode = pHead,Position = 0; pNode != 0;
pNode = pNode->GetNext(),Position++)
if (pNode->GetValue().Info == Value.Info)
break;
if (pNode == NULL)
116

return -1;
else
return Position;
}
void MyList::Insert(ExtendedPacketInfo pi)
{
PINode * pNode = new PINode(pi);
PINode * pCurrent = pHead;
PINode * pNext = 0;
count++;
if(!pHead)
{
pHead = pNode;
return;
}
for(;;)
{
if(!pCurrent->GetNext())
{
pCurrent->SetNext(pNode);
return;
}
pNext = pCurrent->GetNext();
pCurrent = pNext;
}
}
SendersInfoMap.h
#include "ISendersInfoCollection.h"
#include "SendersData.h"
#include <map>
using namespace std;
class SendersInfoMap : public ISendersInfoCollection
{
public:
SendersInfoMap();
SendersInfoMap(const SendersInfoMap& orig);
virtual ~SendersInfoMap();
117

void SaveInfo(PacketInfo sender);


void ChangeInfo(int index,
PacketInfo oldValue,PacketInfo newValue);
int FindSender(PacketInfo sender);
void CountUpPacket(int index,
PacketInfo sender);
private:
map<PacketInfo, SendersData> _storage;
unsigned int _counter;
};
SendersInfoMap.cpp
#include "SendersInfoMap.h"
#include "SendersData.h"
#include <iostream>
using namespace std;
SendersInfoMap::SendersInfoMap()
{
_counter = 0;
}
SendersInfoMap::SendersInfoMap(const SendersInfoMap&
orig)
{
}
SendersInfoMap::~SendersInfoMap()
{
}
void SendersInfoMap::SaveInfo(PacketInfo sender)
{
_storage[sender].Number = _counter;
_storage[sender].Count++;
_counter++;
}
void SendersInfoMap::ChangeInfo(int index,
PacketInfo oldValue, PacketInfo newValue)
{
if(index != -1)
{
SendersData oldData = _storage[oldValue];
_storage.erase(oldValue);
118

_storage[newValue] = oldData;
}
}
int SendersInfoMap::FindSender(PacketInfo sender)
{
map<PacketInfo, SendersData>::iterator result =
storage.find(sender);
if(result != _storage.end())
return (*result).second.Number;
else return -1;
}
void SendersInfoMap::CountUpPacket(int index,
PacketInfo sender)
{
if(index!= -1)
{
_storage[sender].Count++;
}
}
SendersInfoList.h
#include "ISendersInfoCollection.h"
#include "MyList.h"
class SendersInfoList : public
ISendersInfoCollection
{
public:
SendersInfoList();
SendersInfoList(const SendersInfoList& orig);
virtual ~SendersInfoList();
void SaveInfo(PacketInfo sender);
void ChangeInfo(int index,
PacketInfo oldValue,
PacketInfo newValue);
int FindSender(PacketInfo sender);
void CountUpPacket(int index,
PacketInfo sender);
private:
MyList _storage;
};
119

SendersInfoList.cpp
#include "SendersInfoList.h"
SendersInfoList::SendersInfoList()
{
}
SendersInfoList::SendersInfoList(const
SendersInfoList& orig)
{
}
SendersInfoList::~SendersInfoList()
{
}
void SendersInfoList::SaveInfo(PacketInfo sender)
{
_storage.Insert(ExtendedPacketInfo(sender,1));
}
void SendersInfoList::ChangeInfo(int index,
PacketInfo oldValue, PacketInfo newValue)
{
if(index != -1)
{
_storage[index].Info = newValue;
}
}
int SendersInfoList::FindSender(PacketInfo sender)
{
return
storage.Find(ExtendedPacketInfo(sender,1));
}
void SendersInfoList::CountUpPacket(int index,
PacketInfo sender)
{
if(index != -1)
{
_storage[index].Count++;
}
}
120

SendersInfoArray.h
#define STORAGE_SIZE 10000
#include "ISendersInfoCollection.h"
#include "ExtendedPacketInfo.h"
class SendersInfoArray : public
ISendersInfoCollection
{
public:
SendersInfoArray();
SendersInfoArray(const SendersInfoArray& orig);
virtual ~SendersInfoArray();
void SaveInfo(PacketInfo sender);
void ChangeInfo(int index,
PacketInfo oldValue,
PacketInfo newValue);
int FindSender(PacketInfo sender);
void CountUpPacket(int index,
PacketInfo sender);
private:
ExtendedPacketInfo _storage[STORAGE_SIZE];
unsigned int _lastIndex;
};
SendersInfoArray.cpp
#include "SendersInfoArray.h"
#include "ExtendedPacketInfo.h"
SendersInfoArray::SendersInfoArray()
{
_lastIndex = 0;
}
SendersInfoArray::SendersInfoArray(const
SendersInfoArray& orig)
{
}
SendersInfoArray::~SendersInfoArray()
{
}
121

void SendersInfoArray::SaveInfo(PacketInfo sender)


{
_storage[_lastIndex].Info = sender;
_storage[_lastIndex].Count++;
_lastIndex++;
}
void SendersInfoArray::ChangeInfo(int index,
PacketInfo oldValue, PacketInfo newValue)
{
if(index != -1)
{
_storage[index].Info = newValue;
}
}
int SendersInfoArray::FindSender(PacketInfo sender)
{
int result = -1;
for(unsigned int i = 0;i < _lastIndex;i++)
{
if(_storage[i].Info.IPAddress ==
sender.IPAddress &&
_storage[i].Info.PortNumber ==
sender.PortNumber)
{
result = i;
break;
}
}
return result;
}
void SendersInfoArray::CountUpPacket(int index,
PacketInfo sender)
{
if(index!= -1)
{
_storage[index].Count++;
}
}
Main.cpp
122

#include <cstdlib>
#include "ServerTCP.h"
#include <iostream>
#include <vector>
#include <sys/time.h>
#include "SendersInfoMap.h"
#include "SendersInfoArray.h"
#include "SendersInfoList.h"
using namespace std;
void StringSplit(string str, string delim,
vector<string> &results)
{
int cutAt;
while( (cutAt = str.find_first_of(delim)) !=
str.npos )
{
if(cutAt > 0)
{
results.push_back(str.substr(0,cutAt));
}
str = str.substr(cutAt+1);
}
if(str.length() > 0)
{
results.push_back(str);
}
}
float CalcTime(timeval start,timeval end)
{
float time = (end.tv_sec * 1000 +
end.tv_usec/1000.0 start.tv_sec * 1000 start.tv_usec/1000.0);
return time;
}
void AnalyzeTime(float current, float& min,float&
max, float& sum)
{
if(current < min)
min = current;
123

if(current > max)


max = current;
sum += current;
}
int main()
{
string receivedMessage;
ISendersInfoCollection* sendersInfo;
vector<string> messageParts;
timeval start, end;
float chCurrent, chMax=0, chMin=1000, chAvg,
fCurrent, fMax=0, fMin = 1000, fAvg;
float chSum = 0,fSum = 0;
int index;
unsigned long counter = 0;
unsigned int changingCounter = 0;
short collectionType;
cout << "Choose collection type(1-map, 2-array,
3-list)" << endl;
cin >> collectionType;
switch(collectionType)
{
case 1:
sendersInfo = new SendersInfoMap();
break;
case 2:
sendersInfo = new SendersInfoArray();
break;
case 3:
sendersInfo = new SendersInfoList();
break;
default:
cout << "Incorrect type" << endl;
return 1;
}
cout << "Waiting for clients..." << endl;
ServerTCP server;
while(server.Accept(receivedMessage) == 0 &&
receivedMessage[0] != 'E')
{
124

StringSplit(receivedMessage," ",
messageParts);
PacketInfo sender(
atol(messageParts[0].c_str()),
atoi(messageParts[1].c_str()));
sendersInfo->SaveInfo(sender);
messageParts.clear();
}
cout << "Senders info received successfully"
<< endl;
while(server.Accept(receivedMessage) == 0)
{
if(receivedMessage[0]=='c')
{
StringSplit(receivedMessage," ",
messageParts);
PacketInfo oldVal(
atol(messageParts[1].c_str()),
atoi(messageParts[2].c_str()));
PacketInfo newVal(
atol(messageParts[3].c_str()),
atoi(messageParts[4].c_str()));
if(collectionType != 1)
gettimeofday(&start, NULL);
index = sendersInfo->FindSender(oldVal);
if(index != -1)
{
if(collectionType == 1)
gettimeofday(&start, NULL);
sendersInfo->ChangeInfo(index,
oldVal, newVal);
gettimeofday(&end, NULL);
chCurrent = CalcTime(start,end);
AnalyzeTime(chCurrent,chMin,
chMax,chSum);
changingCounter++;
}
125

messageParts.clear();
}
else
{
StringSplit(receivedMessage," ",
messageParts);
PacketInfo sender(
atol(messageParts[0].c_str()),
atoi(messageParts[1].c_str()));
gettimeofday(&start, NULL);
index = sendersInfo->FindSender(sender);
gettimeofday(&end, NULL);
fCurrent = CalcTime(start,end);
AnalyzeTime(fCurrent,fMin,fMax,fSum);
if(index != -1)
{
sendersInfo->CountUpPacket(index,
sender);
}
messageParts.clear();
}
counter++;
}
cout << "Received " << counter << " packets"
<< endl;
chAvg = chSum / changingCounter;
fAvg = fSum / counter;
cout <<
<<
<<
<<
<<
<<
<<
<<
<<

"Time measuring results:" << endl


"Changing: "<< endl
"Min: " << (float) chMin << " Max: "
(float) chMax
" Avg: " << (float) chAvg << endl
"Search: "<< endl
"Min: " << (float) fMin << " Max: "
(float) fMax
" Avg: " << (float) fAvg << endl;

return 0;
126

6. Agile-
.

: http://agilemanifesto.org/iso/ru/

,
. , :




, , ,
- , .

Kent Beck
Mike Beedle
Arie van Bennekum
Alistair Cockburn
Ward Cunningham
Martin Fowler
James Grenning
Jim Highsmith
Andrew Hunt
Ron Jeffries
Jon Kern
Brian Marick
Robert C. Martin
Steve Mellor
Ken Schwaber
Jeff Sutherland
Dave Thomas
2001,
,
, .

127

7. Agile-
.
: http://agilemanifesto.org/iso/ru/principles.html
:

,
.
, .
Agile-
.
,
.

.
.
, ,
.

, .
.
,
. Agile
.

.
.
,
.


.

128

8.
:
ru.wikipedia.org/wiki/___
:
ChibiOS/RT
XOberon
RTLinux
RTEMS
eCos
Embox
Fiasco
OSA
FreeRTOS
KURT
Phoenix-RTOS
:
Automation Runtime
QNX
RTOS-32
Ardence RTX
ChorusOS
CMX RTOS
DNIX
DMERT
DSOS
embOS (Segger)
FlexOS
HP-1000/RTE
INTEGRITY
ITRON
LynxOS
MERT
MicroC/OS-II
MQX RTOS
Nucleus
OS-9
OSE
OSEK/VDX

Nut/OS
Prex
RTAI
scmRTOS
SHaRK
TNKernel
uOS
TRON Project
Xenomai
BeRTOS
ART-Linux

OSEKtime
PDOS
Phar Lap ETS
PikeOS
Portos
pSOS
REX
RMX
RSX-11
RT-11
RTOS-UH
RTXC
Salvo RTOS
SINTRAN III
ThreadX
VRTX
VxWorks/Tornado
Windows CE
nOS
UNIX-RTR
Virtuoso

129

130

9.

: [3]

Linux OS

OS-9

QNX

Windows
RTX

VXWorks

2.5

10

14

<20

2.5

10

x86,
Power PC,
microSPARC

x86,
Power PC

32-bit x86,
Power PC,
MIPS

x86,
SPARC,
Power PC,
MIPS

x86,
Alpha

, K

4000
(run-time)

24 (ROM)
64 (RAM)

640/4000+
(GUI)

10+

12000/1600
0

131