Memory usage optimization

This commit is contained in:
nuknal
2024-06-15 13:05:42 +08:00
parent 0c17fee9c7
commit 35bf364e97
7 changed files with 84 additions and 22 deletions

View File

@@ -3,7 +3,6 @@ package rrc
import (
"bytes"
"encoding/binary"
"fmt"
"math"
"os"
@@ -161,10 +160,16 @@ func (hist *ProbeHistogram) compute() {
log.Info("total Tij table entries:", nT)
if nT != int64(hist.probes*MaxGrayLevel) {
log.Warn("error in computing Tij table, some values are not satisfied")
log.Warn("error in computing Tij table, some values are not satisfied, nT:", nT,
"probes*MaxGrayLevel:", hist.probes*MaxGrayLevel)
}
}
const (
CheckPointProbe = 1000
CheckPointGray = 15000
)
func (hist *ProbeHistogram) saveLUT(fLUT string) error {
file, err := os.Create(fLUT)
if err != nil {
@@ -173,16 +178,14 @@ func (hist *ProbeHistogram) saveLUT(fLUT string) error {
defer file.Close()
for i := 0; i < hist.probes; i++ {
binary.Write(file, binary.LittleEndian, hist.Tmat[i])
if i == CheckPointProbe {
log.Infof("Probes *, LUT check point [%d][%d]: %d", i, CheckPointGray, hist.Tmat[i][CheckPointGray])
}
}
return nil
}
const (
CheckPointProbe = 1000
CheckPointGray = 15000
)
func LoadLUT(fLUT string, probes int) ([][]uint16, error) {
data, err := os.ReadFile(fLUT)
if err != nil {
@@ -214,7 +217,15 @@ func (hist *ProbeHistogram) sum(hists []*ProbeHistogram) {
hist.m_l[gray] += h.m_l[gray]
}
}
fmt.Println("Hist.M:", hist.M)
fmt.Println("Hist.probes:", hist.probes)
}
func (hist *ProbeHistogram) free() {
hist.N_i = nil
hist.n_ik = nil
hist.p_ik = nil
hist.m_l = nil
hist.P_l = nil
hist.S_ik = nil
hist.V_l = nil
hist.Tmat = nil
}