Make the memory printout more portable and readable.

Avoid integers, uses doubles.
This commit is contained in:
Holger Vogt 2026-04-28 20:17:01 +02:00
parent cb1a29b8c0
commit 51ebf841ac
1 changed files with 14 additions and 13 deletions

View File

@ -130,31 +130,32 @@ OUTpBeginPlot(CKTcircuit *circuitPtr, JOB *analysisPtr,
if (!cp_getvar("no_mem_check", CP_BOOL, NULL, 0)) { if (!cp_getvar("no_mem_check", CP_BOOL, NULL, 0)) {
/* Estimate the required memory */ /* Estimate the required memory */
int timesteps = ft_curckt->ci_ckt->CKTtimeListSize; double timesteps = ft_curckt->ci_ckt->CKTfinalTime / ft_curckt->ci_ckt->CKTstep;
size_t memrequ = (size_t)n * timesteps * sizeof(double); double dmemrequ = timesteps * (double)n * sizeof(double);
size_t memavail = getAvailableMemorySize(); double dmemavail = (double)getAvailableMemorySize();
double dmemrequ = (double)memrequ; char *cmemrequ = eng(dmemrequ, 6, FALSE, TRUE);
double dmemavail = (double)memavail; char *cmemavail = eng(dmemavail, 6, FALSE, TRUE);
char *cmemrequ = eng(dmemrequ, 9, FALSE, TRUE); char *ctimesteps = eng(timesteps, 6, TRUE, FALSE);
char *cmemavail = eng(dmemavail, 9, FALSE, TRUE); if (dmemrequ > dmemavail) {
if (memrequ > memavail) {
#ifdef _WIN32 #ifdef _WIN32
fprintf(stderr, "\nError: memory required (%sB), made of\n" fprintf(stderr, "\nError: memory required (%sB), made of\n"
" %d nodes and approximately %d time steps,\n" " %d nodes and approximately %s time steps,\n"
" is more than the memory available (%sB)!\n", " is more than the memory available (%sB)!\n",
cmemrequ, n, timesteps, cmemavail); cmemrequ, n,ctimesteps, cmemavail);
fprintf(stderr, "Setting the output memory is not possible.\n"); fprintf(stderr, "Setting the output memory is not possible.\n");
tfree(cmemrequ); tfree(cmemrequ);
tfree(cmemavail); tfree(cmemavail);
tfree(ctimesteps);
controlled_exit(1); controlled_exit(1);
#else #else
fprintf(stderr, "\nWarning: memory required (%sB), made of\n" fprintf(stderr, "\nWarning: memory required (%sB), made of\n"
" %d nodes and approximately %d time steps,\n" " %d nodes and approximately %s time steps,\n"
" is more than the DRAM memory available (%sB)!\n", " is more than the DRAM memory available (%sB)!\n",
cmemrequ, n, timesteps, cmemavail); cmemrequ, n, ctimesteps, cmemavail);
fprintf(stderr, "Swapping data to SSD may slow down the simulation.\n"); fprintf(stderr, " Swapping data to SSD may slow down the simulation.\n");
tfree(cmemrequ); tfree(cmemrequ);
tfree(cmemavail); tfree(cmemavail);
tfree(ctimesteps);
#endif #endif
} }
} }