Forum > General

[SOLVED] discarding an array

(1/3) > >>

robert rozee:
perhaps a silly question: is there any way to discard a typed constant array at runtime?

the situation is i have several rather large arrays, of the form

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Const  bindata : Array[0..1066635] of byte = (      31,139,  8,  8,242,169,120,100,  0,  3, 71, 70, 88,116,101,114,109,       0,172,157,  7,120, 85,197,246,197,111, 66,132,  0,210,123, 15,160,     244,222, 59,161,247, 94, 85, 48,  4,114, 19,  2, 33,  9, 73, 40,210,    ...Const  patch1 : Array[0..315288] of byte = (      31,139,  8,  8,237,165,120,100,  0,  3,112, 49,100,105,102,102,115,      46,116,120,116,  0,236,253,187,210,236, 58,175, 45,  8,250,124,138,     109,118, 25, 43, 66, 41,165,164, 76,183,162,162,204,118,250,  9,242,... etc.
there have been generated by bin2obj. i use them at the start of my application, but thereafter they are no longer needed. indeed, within a second or two my application does:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  ExecuteProcess(TempName, '');                                // run binary
in order to keep things as tidy as possible, it would be nice to free up the arrays before essentially going dormant. any suggestions on how to achieve this? the application is strictly linux/unix only if that helps.


cheers,
rob   :-)

Eugene Loza:
I don't know any way to discard a constant in Pascal... I wonder if there is any reason you don't want to have them as dynamic arrays? You literally just replace "const" with "var" and don't even have to make any conversion. Like this:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var  A: array of Byte = (1,2,3,4);begin  //Work with A  A := nil; // A will be free nowend.
Note: this may be a new feature of FPC 3.3.1

jamie:
Link that data in as a resource and load it when needed into dynamic array.

It will still be attached to the EXE but not in memory once you free the dynamic array.

PascalDragon:

--- Quote from: robert rozee on June 01, 2023, 07:53:24 pm ---perhaps a silly question: is there any way to discard a typed constant array at runtime?
--- End quote ---

No, for static typed constant arrays this is not possible, they are part of the binary's (readonly) data section.

jcmontherock:
@Eugene:

...Or SetLength(A, 0);

Navigation

[0] Message Index

[#] Next page

Go to full version