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
This commit is contained in:
2024-11-21 00:10:14 +03:00
parent caa7880cc4
commit 9ab46e4afc
4 changed files with 37 additions and 19 deletions

View File

@@ -23,7 +23,7 @@
const size_t minAlloc = 64; const size_t minAlloc = 64;
const size_t maxPoTAlloc = 4_MiB; const size_t maxPoTAlloc = 64_MiB;
size_t _PIContainerConstantsBase::calcMinCountPoT(size_t szof) { size_t _PIContainerConstantsBase::calcMinCountPoT(size_t szof) {
@@ -39,10 +39,12 @@ size_t _PIContainerConstantsBase::calcMinCountPoT(size_t szof) {
size_t _PIContainerConstantsBase::calcMaxCountForPoT(size_t szof) { size_t _PIContainerConstantsBase::calcMaxCountForPoT(size_t szof) {
// printf("calcMaxCountForPoT sizeof = %d, size = %d\n", szof, maxPoTAlloc / szof);
return maxPoTAlloc / szof; return maxPoTAlloc / szof;
} }
size_t _PIContainerConstantsBase::calcStepAfterPoT(size_t szof) { size_t _PIContainerConstantsBase::calcStepAfterPoT(size_t szof) {
// printf("calcStepAfterPoT sizeof = %d, size = %d\n", szof, calcMaxCountForPoT(szof));
return calcMaxCountForPoT(szof); return calcMaxCountForPoT(szof);
} }

View File

@@ -2575,17 +2575,25 @@ private:
pid_data = nullptr; pid_data = nullptr;
} }
inline size_t asize(ssize_t s) { inline size_t asize(ssize_t ss) {
if (s <= 0) return 0; if (ss <= 0) return 0;
if (pid_rsize * 2 >= size_t(s) && pid_rsize < size_t(s)) { size_t s = ss;
if (s <= _PIContainerConstants<T>::maxCountForPoT()) {
if (pid_rsize * 2 >= s && pid_rsize < s) {
return pid_rsize * 2; return pid_rsize * 2;
} }
size_t t = _PIContainerConstants<T>::minCountPoT(); ssize_t t = _PIContainerConstants<T>::minCountPoT();
s -= 1; s -= 1;
while (s >> t) { while (s >> t)
++t; ++t;
}
return (1 << t); return (1 << t);
} else {
size_t ret = pid_rsize;
while (ret < s)
ret += _PIContainerConstants<T>::stepAfterPoT();
return ret;
}
return 0;
} }
template<typename T1 = T, typename std::enable_if<!std::is_trivially_copyable<T1>::value, int>::type = 0> template<typename T1 = T, typename std::enable_if<!std::is_trivially_copyable<T1>::value, int>::type = 0>

View File

@@ -2461,6 +2461,7 @@ private:
inline size_t asize(size_t s) { inline size_t asize(size_t s) {
if (s == 0) return 0; if (s == 0) return 0;
if (s <= _PIContainerConstants<T>::maxCountForPoT()) {
if (piv_rsize * 2 >= s && piv_rsize < s) { if (piv_rsize * 2 >= s && piv_rsize < s) {
return piv_rsize * 2; return piv_rsize * 2;
} }
@@ -2469,6 +2470,13 @@ private:
while (s >> t) while (s >> t)
++t; ++t;
return (1 << t); return (1 << t);
} else {
size_t ret = piv_rsize;
while (ret < s)
ret += _PIContainerConstants<T>::stepAfterPoT();
return ret;
}
return 0;
} }
template<typename T1 = T, typename std::enable_if<!std::is_trivially_copyable<T1>::value, int>::type = 0> template<typename T1 = T, typename std::enable_if<!std::is_trivially_copyable<T1>::value, int>::type = 0>

View File

@@ -360,7 +360,6 @@ void usage() {
int main(int argc, char * argv[]) { int main(int argc, char * argv[]) {
sys_mon.startOnSelf();
// piDebug = false; // piDebug = false;
PICLI cli(argc, argv); PICLI cli(argc, argv);
cli.addArgument("help"); cli.addArgument("help");
@@ -375,6 +374,7 @@ int main(int argc, char * argv[]) {
usage(); usage();
return 0; return 0;
} }
sys_mon.startOnSelf();
PIString name = cli.argumentValue("name"); PIString name = cli.argumentValue("name");
PIString sip = cli.argumentValue("address"); PIString sip = cli.argumentValue("address");
PISingleApplication * sapp = 0; PISingleApplication * sapp = 0;