diff --git a/libs/main/containers/picontainers.cpp b/libs/main/containers/picontainers.cpp
new file mode 100644
index 00000000..f887160a
--- /dev/null
+++ b/libs/main/containers/picontainers.cpp
@@ -0,0 +1,34 @@
+/*
+ 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 .
+*/
+
+#include "picontainers.h"
+
+
+const ssize_t minAlloc = 64;
+
+
+ssize_t _PIContainerConstantsBase::calcMinCountPoT(ssize_t szof) {
+ ssize_t ret = 0, elc = 1;
+ while (elc * szof < minAlloc) {
+ elc *= 2;
+ ++ret;
+ }
+ //printf("calcMinCount sizeof = %d, min_count = %d, pot = %d\n", szof, elc, ret);
+ return ret;
+}
diff --git a/libs/main/containers/picontainers.h b/libs/main/containers/picontainers.h
index 81c3c1a8..c917494a 100644
--- a/libs/main/containers/picontainers.h
+++ b/libs/main/containers/picontainers.h
@@ -63,6 +63,18 @@ private:
};
+class PIP_EXPORT _PIContainerConstantsBase {
+public:
+ static ssize_t calcMinCountPoT(ssize_t szof);
+};
+
+template
+class _PIContainerConstants {
+public:
+ static ssize_t minCountPoT() {static ssize_t ret = _PIContainerConstantsBase::calcMinCountPoT(sizeof(T)); return ret;}
+};
+
+
//! \brief
//! \~english Template reverse wrapper over any container
//! \~russian Шаблонная функция обертки любого контейнера для обратного доступа через итераторы
diff --git a/libs/main/containers/pideque.h b/libs/main/containers/pideque.h
index 8f8cab54..deb8c09d 100644
--- a/libs/main/containers/pideque.h
+++ b/libs/main/containers/pideque.h
@@ -2280,10 +2280,9 @@ private:
if (pid_rsize + pid_rsize >= size_t(s) && pid_rsize < size_t(s)) {
return pid_rsize + pid_rsize;
}
- ssize_t t = 0, s_ = s - 1;
- while (s_ >> t) {
+ ssize_t t = _PIContainerConstants::minCountPoT(), s_ = s - 1;
+ while (s_ >> t)
++t;
- }
return (1 << t);
}
template= s && piv_rsize < s) {
return piv_rsize + piv_rsize;
}
- ssize_t t = 0, s_ = s - 1;
- while (s_ >> t) ++t;
+ ssize_t t = _PIContainerConstants::minCountPoT(), s_ = s - 1;
+ while (s_ >> t)
+ ++t;
return (1 << t);
}
templateAdapterName);
ci.index = pAdapter->Index;
@@ -1031,8 +1030,8 @@ PIEthernet::InterfaceList PIEthernet::interfaces() {
IP_ADDR_STRING * as = &(pAdapter->IpAddressList);
while (as) {
// piCout << "[pAdapter]" << ci.name << PIString(as->IpAddress.String);
- ci.address = PIString(as->IpAddress.String);
- ci.netmask = PIString(as->IpMask.String);
+ ci.address = PIStringAscii(as->IpAddress.String);
+ ci.netmask = PIStringAscii(as->IpMask.String);
if (ci.address == "0.0.0.0") {
as = as->Next;
continue;
@@ -1053,7 +1052,7 @@ PIEthernet::InterfaceList PIEthernet::interfaces() {
}
}
if (pAdapterInfo)
- HeapFree(GetProcessHeap(), 0, (pAdapterInfo));
+ HeapFree(GetProcessHeap(), 0, pAdapterInfo);
#else
#ifdef MICRO_PIP
#else
@@ -1213,10 +1212,16 @@ int PIEthernet::ethErrorCore() {
PIString PIEthernet::ethErrorString() {
#ifdef WINDOWS
- char * msg;
+ char * msg = nullptr;
int err = WSAGetLastError();
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&msg, 0, NULL);
- return "code " + PIString::fromNumber(err) + " - " + PIString(msg);
+ PIString ret = PIStringAscii("code ") + PIString::fromNumber(err) + PIStringAscii(" - ");
+ if (msg) {
+ ret += PIString::fromSystem(msg).trim();
+ LocalFree(msg);
+ } else
+ ret += '?';
+ return ret;
#else
return errorString();
#endif
diff --git a/libs/main/system/pisystemmonitor.cpp b/libs/main/system/pisystemmonitor.cpp
index cb1647b1..0efb651d 100644
--- a/libs/main/system/pisystemmonitor.cpp
+++ b/libs/main/system/pisystemmonitor.cpp
@@ -356,6 +356,7 @@ void PISystemMonitor::run() {
void PISystemMonitor::gatherThread(llong id) {
PISystemMonitor::ThreadStats ts;
+ if (id == 0) return;
ts.id = id;
#ifdef MICRO_PIP
ts.name = tbid.value(id, "");
@@ -386,11 +387,12 @@ void PISystemMonitor::gatherThread(llong id) {
PISystemTime ct = PISystemTime::current();
FILETIME times[4];
HANDLE thdl = OpenThread(THREAD_QUERY_INFORMATION, FALSE, DWORD(id));
- if (thdl == NULL) {
+ if (!thdl) {
piCout << "[PISystemMonitor] gatherThread(" << id << "):: OpenThread() error:" << errorString();
return;
}
if (GetThreadTimes(thdl, &(times[0]), &(times[1]), &(times[2]), &(times[3])) == 0) {
+ CloseHandle(thdl);
piCout << "[PISystemMonitor] gatherThread(" << id << "):: GetThreadTimes() error:" << errorString();
return;
}