-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix estimate_memory_usage() function (#900)
- Use capacity instead of size in estimate_memory_usage() - Extract calculate_memory_for_copying() which uses size (old estimate_memory_usage())
- Loading branch information
Showing
5 changed files
with
68 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
@ok | ||
<?php | ||
|
||
function test_vector() { | ||
#ifndef KPHP | ||
// sizeof(array_inner_control) + buf_size * sizeof(int64_t) | ||
var_dump(32 + 2 * 8); | ||
var_dump(32 + 2 * 8); | ||
var_dump(32 + 4 * 8); | ||
var_dump(32 + 4 * 8); | ||
var_dump(32 + 8 * 8); | ||
var_dump(32 + 8 * 8); | ||
var_dump(32 + 8 * 8); | ||
var_dump(32 + 8 * 8); | ||
var_dump(32 + 16 * 8); | ||
var_dump(32 + 16 * 8); | ||
return; | ||
#endif | ||
$v = []; | ||
for ($i = 0; $i < 10; ++$i) { | ||
$v[] = 42; | ||
var_dump(estimate_memory_usage($v)); | ||
} | ||
} | ||
|
||
function test_map() { | ||
#ifndef KPHP | ||
// sizeof(array_inner_fields_for_map) + sizeof(array_inner_control) + buf_size * sizeof(array_bucket) | ||
var_dump(16 + 32 + 11 * 32); | ||
var_dump(16 + 32 + 33 * 32); | ||
return; | ||
#endif | ||
$m = []; | ||
for ($i = 0; $i < 7; ++$i) { | ||
$m[$i + 1] = 42; | ||
} | ||
var_dump(estimate_memory_usage($m)); | ||
$m[23] = 42; | ||
var_dump(estimate_memory_usage($m)); | ||
} | ||
|
||
test_vector(); | ||
test_map(); |