FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
livecode/libfoundation/test/test_memory.cpp at develop · livecode/livecode · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
This repository was archived by the owner on Aug 31, 2021. It is now read-only.
livecode
/
livecode
Public archive
Notifications
You must be signed in to change notification settings
Fork
223
Star
517
Code
Pull requests
189
Actions
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
livecode
/
libfoundation
/
test
/
test_memory.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
94 lines (81 loc) · 2.92 KB
Breadcrumbs
livecode
/
libfoundation
/
test
/
test_memory.cpp
Copy path
File metadata and controls
94 lines (81 loc) · 2.92 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
Copyright (C) 2003-2015 LiveCode Ltd.
This file is part of LiveCode.
LiveCode is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License v3 as published by the Free
Software Foundation.
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with LiveCode. If not see <http://www.gnu.org/licenses/>.
*/
#
include
"
gtest/gtest.h
"
#
include
"
foundation.h
"
#
include
"
foundation-unicode.h
"
#
include
"
foundation-auto.h
"
#
include
"
foundation-private.h
"
#
define
GTEST_COUT
std::cerr <<
"
[ ] [ INFO ]
"
template
<
typename
T>
void
_memory_value_size
(
const
char
*p_name)
{
GTEST_COUT
<<
"
sizeof(
"
<< p_name <<
"
) =
"
<<
sizeof
(T) << std::endl;
}
void
_memory_malloc_size
(
int
p_size)
{
char
*t_blocks[
16
];
for
(
int
i =
0
; i <
16
; i++)
t_blocks[i] = (
char
*)
malloc
(p_size);
GTEST_COUT
<<
"
malloc deltas for
"
<< p_size <<
"
=
"
;
for
(
int
i =
1
; i <
16
; i++)
std::cerr <<
"
"
<< (t_blocks[i] - t_blocks[i -
1
]);
std::cerr << std::endl;
for
(
int
i =
0
; i <
16
; i++)
free
(t_blocks[i]);
}
TEST
(memory, information)
{
/*
Dump out the struct sizes of the core value types
*/
_memory_value_size<__MCNull>(
"
MCNull
"
);
_memory_value_size<__MCBoolean>(
"
MCBoolean
"
);
_memory_value_size<__MCNumber>(
"
MCNumber
"
);
_memory_value_size<__MCName>(
"
MCName
"
);
_memory_value_size<__MCString>(
"
MCString
"
);
_memory_value_size<__MCData>(
"
MCData
"
);
_memory_value_size<__MCArray>(
"
MCArray
"
);
_memory_value_size<__MCList>(
"
MCList
"
);
_memory_value_size<__MCSet>(
"
MCSet
"
);
_memory_value_size<__MCProperList>(
"
MCProperList
"
);
/*
Check the veracity of the malloc implementation with regards small objects
*/
_memory_malloc_size
(
8
);
_memory_malloc_size
(
16
);
_memory_malloc_size
(
24
);
_memory_malloc_size
(
32
);
_memory_malloc_size
(
48
);
_memory_malloc_size
(
64
);
}
TEST
(memory, sizes)
{
#
ifdef
__32_BIT__
EXPECT_EQ
(
sizeof
(__MCNull),
8
);
EXPECT_EQ
(
sizeof
(__MCBoolean),
8
);
EXPECT_EQ
(
sizeof
(__MCNumber),
16
);
EXPECT_EQ
(
sizeof
(__MCName),
24
);
EXPECT_EQ
(
sizeof
(__MCString),
32
);
EXPECT_EQ
(
sizeof
(__MCData),
20
);
EXPECT_EQ
(
sizeof
(__MCArray),
16
);
EXPECT_EQ
(
sizeof
(__MCList),
16
);
EXPECT_EQ
(
sizeof
(__MCSet),
16
);
EXPECT_EQ
(
sizeof
(__MCProperList),
16
);
#
else
EXPECT_EQ
(
sizeof
(__MCNull),
8
);
EXPECT_EQ
(
sizeof
(__MCBoolean),
8
);
EXPECT_EQ
(
sizeof
(__MCNumber),
16
);
EXPECT_EQ
(
sizeof
(__MCName),
32
);
EXPECT_EQ
(
sizeof
(__MCString),
32
);
EXPECT_EQ
(
sizeof
(__MCData),
24
);
EXPECT_EQ
(
sizeof
(__MCArray),
24
);
EXPECT_EQ
(
sizeof
(__MCList),
24
);
EXPECT_EQ
(
sizeof
(__MCSet),
24
);
EXPECT_EQ
(
sizeof
(__MCProperList),
24
);
#
endif
}
Back
|
FazBrowse Home
|
New Git URL