Current archive: 2011.12.18;
string constants Find similar branches← →
Gu (2011-09-01 18:58) 
The application uses many string constants, which are used in many of its modules. Question: how will it be more correct to declare them: at the beginning of the main module (all others use it) in the Consts section or in the Resourcestring section? Are there any big differences between them and does it affect the speed and memory consumption when loading the application and working?
Ega23 © (2011-09-01 19:28) 
> at the beginning of the main module
_Юрий (2011-09-01 19:29) 
> in the Consts section or in the Resourcestring section?
The difference is in fact whether they will be constants or strings in the resource.
The differences between them are, of course, large.
Resource strings are usually made when application localization is required.
Gu (2011-09-01 20:06) 
Those. I understand that in the case of Resourcestring, the program, when used in procedures, will climb its resources each time (i.e., perform a file operation), and in the case of constants, will all operations be performed in memory?
Anatoly Podgoretsky © (2011-09-01 20:07) 
> Gu (01.09.2011 18: 58: 00) 
Resourcestring is more correct and optimal, the system takes care of this.
Rouse_ © (2011-09-01 20:07) 
In both cases, the operation is performed in memory.
Anatoly Podgoretsky © (2011-09-01 20:20) 
> Rouse_ (01.09.2011 20: 07: 05) 
Only in the first in memory is everything that can load, but with resources on
Rouse_ © (2011-09-01 20:50) 
> Anatoly Podgoretsky © (01.09.11 20: 20) 
> Only in the first in my memory is everything that she can load, but with
> resource requirements
That is not, the resource section is loaded into the memory entirely and work directly with the resource is carried out on the offset, the same eggs, only in profile ...
Anatoly Podgoretsky © (2011-09-01 20:52) 
> Rouse_ (01.09.2011 20: 50: 07) 
Loaded on 16 lines.
Rouse_ © (2011-09-01 21:00) 
Entirely loaded :) If the image of the executable file was not loaded into the memory together with all sections, including the resource section, then such a concept as an image dump would not be possible.
Rouse_ © (2011-09-01 21:01) 
PS: compile this demo here, it clearly shows everything, where and how: http://rouse.drkb.ru/winapi.php#pmm
Игорь Шевченко © (2011-09-01 22:48) 
Rouse_ © (01.09.11 21: 00) 
Is a 100-megabyte installer also loaded entirely into memory?
here I have a file:
Turbo Dump Version 220.127.116.11 Copyright (c) 1988-2009 Embarcadero Technologies, Inc.
Display of File windowsxp.x86.fre.rtm.symbols.exe
# Name VirtSize RVA PhysSize Phys off Flags
- -------- -------- -------- -------- -------- --------
01 .text 000085F2 00001000 00008600 00000400 60000020 [CER]
02 .data 00001BE4 0000A000 00000400 00008A00 C0000040 [IRW]
03 .rsrc 095D4000 0000C000 095D3E00 00008E00 40000040 [IR]
Will all sections be displayed immediately upon startup?
Rouse_ © (2011-09-02 01:26) 
Installer? And in what way does it relate to the executable file? Boot stub and section transferred to MSI service
Игорь Шевченко © (2011-09-02 09:49) 
> And in what way does it relate to the executable file?
has a PE format
Rouse_ © (2011-09-02 10:38) 
> Igor Shevchenko © (01.09.11 22: 48) 
By the way, it is this installer that yes, it is loaded entirely ...
Игорь Шевченко © (2011-09-02 10:38) 
> By the way, it is this installer that yes, it is loaded entirely.
Игорь Шевченко © (2011-09-02 10:40) 
To begin with, it would be nice to agree on terminology: what does it mean to "load"?
Rouse_ © (2011-09-02 10:41) 
> Igor Shevchenko © (02.09.11 10: 38) 
> prove it
han_malign (2011-09-02 10:53) 
> prove it
Игорь Шевченко © (2011-09-02 12:56) 
This is all good, but where is it written that they are "loaded"? At least in one picture?
They lie calmly on the disk, as do the unused pages of the code segment.
Rouse_ © (2011-09-02 13:09) 
> Igor Shevchenko © (02.09.11 12: 56) 
> This is all good, but where does it say that they are "loaded"? At least
> one picture?
> Lying quietly on your disk, like unused pages
> code segment.
Well, the point is that if you remove the process dump and run FileMon at the same time, it will be clearly visible that data is not read from the image of the file on disk.
Игорь Шевченко © (2011-09-02 13:15) 
Rouse_ © (02.09.11 13: 09) 
And if you start FileMon before starting the process? Will it show a reading of the TOTAL executable?
Rouse_ © (2011-09-02 13:17) 
Yes, the whole file will be read.
Slym © (2011-09-02 13:26) 
Rouse_ © (02.09.11 13: 17) 
disable antivirus so as not to scan first
Rouse_ © (2011-09-02 13:32) 
I tested on a virtual machine, I have a symbol file there with a site, there is no antivirus ...
Игорь Шевченко © (2011-09-02 13:32) 
for the sake of interest, I launched FileMon and the specified file. Read all 146 megabytes did not see. And I did not expect to see it, since in books, starting with Richter, it is written that executable files are read as needed, and not entirely at startup.
Rouse_ © (2011-09-02 13:33) 
Did you see the reading during the dump?
Rouse_ © (2011-09-02 13:34) 
By the way, didn’t you see the upload of the entire resource section to a temporary folder? I wonder then, how is she so without a full reading of that?
Игорь Шевченко © (2011-09-02 13:37) 
> Did you see the reading when dumping?
What is a dump?
Rouse_ © (2011-09-02 13:40) 
Maxwell described this process as follows: http://www.netlib.narod.ru/library/book0010/ch08_07.htm
Игорь Шевченко © (2011-09-02 13:48) 
> Maxwell described this process as follows
"The most common Linux binary format is ELF, so let's look at how the ELF binary handler performs a memory dump.
How do you command me to understand?
I can tell you more - if you start FileMon and copy the file, the read operations of the entire file will also be shown. You access all pages of memory in the address space of the process, causing them to be mapped to physical memory.
Rouse_ © (2011-09-02 13:59) 
> How do you command me to understand?
The link was given as a description of what a memory dump is.
> You access all pages of memory in the address space
> process, causing them to be mapped to physical memory.
Where do they appear from? Where are not displayed data stored?
I’m telling you again, you said you didn’t see the reads of the whole file.
Okay, let's say. But the problem is that at startup the installer of the symbols unloads the files eula.txt simbols.cab simbols.cat, etc., stored in the resource section into a temporary folder.
The question is, where did he get them, the reading of the file wasn’t according to your statement? Or maybe all the same, the LoadImage record with the size indicating going before the upload is hinting to us?
Игорь Шевченко © (2011-09-02 15:06) 
> Where do they appear from? Where are not displayed data stored?
> The question is, where did he get them,
At the time of accessing this data, there was a reading. Through the memory manager.
Rouse_ © (2011-09-02 15:11) 
> at the time of accessing this data, there was a reading
But FileMon didn’t show it ... I see.
Юрий Зотов © (2011-09-02 15:20) 
If I understood Richter correctly, then not a single file (including executable files) FULLY in RAM is ever loaded. It is displayed on the AP of the process, and in RAM it is loaded per page, as needed (of course, taking into account the page cache as well). That is, the disk file itself is, as it were, used as a kind of swap.
Юрий Зотов © (2011-09-02 15:22) 
Unless the whole file fits in one page ... then it will load completely, of course.
Rouse_ © (2011-09-02 15:39) 
Yes, it’s all clear, I’m just talking about virtual memory, and not about physical ...
Inovet © (2011-09-02 15:41) 
>  Yuri Zotov © (02.09.11 15: 20)
> the file is being used as a kind of swap
Isn't the mechanism the same as in the swap. It's just that the file is already on disk.
Inovet © (2011-09-02 15:44) 
>  Rouse_ © (02.09.11 15: 39)
> I’m talking about virtual memory
So it’s virtual, so you don’t have to read it in RAM without need. Why, if the data or code may never be needed
Игорь Шевченко © (2011-09-02 16:30) 
FileMon shows reading into physical memory :)
Anatoly Podgoretsky © (2011-09-02 16:50) 
> Yuri Zotov (02.09.2011 15: 20: 34) 
resourcestring is just like that, does not chase a swap, it is part of the swap itself
Anatoly Podgoretsky © (2011-09-02 16:52) 
> Rouse_ (02.09.2011 15: 39: 36) 
and we, as it were, talked about the physical all the time. With virtual it’s clear, so
there is nothing to load, there it is necessary to map to physical memory.
Германн © (2011-09-03 00:50) 
> Anatoly Podgoretsky © (02.09.11 16: 52) 
>> Rouse_ (02.09.2011 15: 39: 36) 
> and we, as it were, about the physical all the time talking.
Well, why were you?
According to sabzh, there is practically no difference.
Германн © (2011-09-03 00:54) 
In general (IMHO) the subject itself is stupid.
Well, it would be about mathematical processing of a physical experiment. Or about mathematical modeling of something.
_Юрий (2011-09-04 13:42) 
A little off topic
for some time now I stopped doing this altogether - to take out a bunch of constants in one place so that I could use them everywhere.
Because when their number increases greatly, it becomes difficult to find anything, there is no grouping, formalization of possible parameters is absent.
Therefore, I began to do it differently: hide the constants in the code, and already put it in the general modules. Most often, these constants are error textures.
Then instead, for example
SFileNotFound = "File% s not found";
if not FileExist (fileName) then
raise EPathException.CreateFmt (SFileNotFound, [fileName]);
I'm writing something like
EPathException = class (Exception)
constructor FileNotFound (fileName: string);
constructor EPathException.FileNotFound (fileName: string);
SFileNotFound = "File% s not found";
CreateFmt (SFileNotFound, [fileName]);
if not FileExist (fileName) then
raise EPathException.FileNotFound (fileName);
There can be many designers - one for each case.
If the constant is some name, then it is better to transfer it to the corresponding class (as a nested constant, and if the Delphi version does not allow it, then as a class function). For the same reasons.
Look, maybe this approach will seem more suitable for you.
Игорь Шевченко © (2011-09-04 14:24) 
_Yuri (04.09.11 13: 42) 
VCL / RTL offer another way - by units (rtl, db, ...) consts
Where is the middle ground?
(Well, to the point - I don’t understand the use of resourcestring in a non-localizable project. I don’t understand the use of resourcestring because I can’t manage it - I don’t know the resource identifiers, and leave it all to ITE - I have a bad relationship with him, from the old versions, where it was buggy with terrible force, maybe these glitches were removed, but the sediment remained).
Anatoly Podgoretsky © (2011-09-04 14:53) 
> Igor Shevchenko (04.09.2011 14: 24: 45) 
Maybe, but on the seven glitches were not detected, in addition, localization
lends itself not only to its code, but also a free gift in addition, also
A resourvestring makes sense to use because of some optimality
the system’s work, but you probably already know that, I probably read it with Richter.
Then, if you want to localize, you won’t have to redo anything, but ITE
localization at the level, not only texts.
Игорь Шевченко © (2011-09-04 15:08) 
Anatoly Podgoretsky © (04.09.11 14: 53) 
I don’t know if they solved the problem (I read that I somehow solved) - there are texts that need to be translated by an external translator
(the Chinese developer does not know) so that he does not have access to the source texts and that he does not need to install software.
Anatoly Podgoretsky © (2011-09-04 15:55) 
> Igor Shevchenko (04.09.2011 15: 08: 47) 
No installation at all. We need a compelling editor of Delphi resources, i.e.
see and change forms, at least such an editor is in ITE, it is in
standalone option. The main problem with ITE is psychological
Eraser © (2011-09-04 21:46) 
http://matrix.kladovka.net.ru/index.php?page=downloads&categ=other&pagenum=1 см. "multilang.zip". Мощнейшее и простое средство для работы с локализацией. Правда для полноценной работы я туда привинтил слабенькую поддержку коллекций, но зато теперь фактически универсальный инструмент. четвертый год работает отлично. а ITE мастдай, это с самого начало понятно. что за локализатор такой, которому исходники подавай? это противоречит всей концепции локализации проектов, т.к. обычно локализацию на аутсорс отдают.
_Юрий (2011-09-05 21:39) 
> Igor Shevchenko © (04.09.11 14: 24) 
> VCL / RTL offer another way - by units (rtl, db, ...) consts
This is a very old code, since then the experience of mankind in programming has become 15 years more. Now, I think they would have written differently.
According to resourcestring without localization - I agree, in my opinion nafig is not necessary.
Игорь Шевченко © (2011-09-05 23:02) 
_Yuri (05.09.11 21: 39) 
> Now, I think they would have written differently.
Not sure. In them, each consts unit refers to a specific package, when dividing vcl into vcl and rtl, the constants are also divided into consts (vcl) and rtlconsts
These units contain just localizable constants, maybe this is due to ITE, so that all constants of this type are brought together, maybe with something else, I don’t know, but look for laziness.
I mean, the Borlands have a goal in such an organization of constants.
_Юрий (2011-09-06 20:24) 
> Igor Shevchenko © (05.09.11 23: 02) 
I would venture to suggest that such a branch arose even before ITE.
Which appeared in my opinion in Delphi5.
While he was not there, it was possible to replace the unit with constants with your own, and thus somehow solve the localization problem.
If the constants were smeared by code, this would not have taken off.
Pages: 1 2 whole branch
Current archive: 2011.12.18;
Memory: 0.76 MB
Time: 0.037 c