Files
pip/libs/main/containers/picontainers.cpp
peri4 9ab46e4afc version 4.4.1
PIVector and PIDeque now growth to 64 MiB with PoT, then increments size by 64 MiB
in case of large containers it significantly save memory
2024-11-21 00:10:14 +03:00

51 lines
1.5 KiB
C++

/*
PIP - Platform Independent Primitives
Base macros for generic containers
Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "picontainers.h"
#include "piliterals_bytes.h"
const size_t minAlloc = 64;
const size_t maxPoTAlloc = 64_MiB;
size_t _PIContainerConstantsBase::calcMinCountPoT(size_t szof) {
size_t ret = 0;
size_t elc = 1;
while (elc * szof < minAlloc) {
elc *= 2;
++ret;
}
// printf("calcMinCount sizeof = %d, min_count = %d, pot = %d\n", szof, elc, ret);
return ret;
}
size_t _PIContainerConstantsBase::calcMaxCountForPoT(size_t szof) {
// printf("calcMaxCountForPoT sizeof = %d, size = %d\n", szof, maxPoTAlloc / szof);
return maxPoTAlloc / szof;
}
size_t _PIContainerConstantsBase::calcStepAfterPoT(size_t szof) {
// printf("calcStepAfterPoT sizeof = %d, size = %d\n", szof, calcMaxCountForPoT(szof));
return calcMaxCountForPoT(szof);
}