I miss the old days in irc when many people were talking about pascal. Most people seem to have disappeared from there. Maybe they died of old age? I don’t know :o:) again? Please stop infesting the forum with posts about IRC, you already hijacked several threads. It should be pretty obvious by now that people don't want to participate in IRC discussions for various reasons. Why do you keep insisting?
The last thing we need to do is divide people up by age. I didn’t take the survey for that reason.
The important question is WHY did most schools stop teaching pascal ??and how to reverse this trend?
As if the lack of universities and employers supporting pascal isn’t enough, outside of this forum people are constantly attacking and trying to discredit pascal. It’s a rare thing to meet someone new who uses Pascal.
I miss the old days in irc when many people were talking about pascal. Most people seem to have disappeared from there. Maybe they died of old age? I don’t know :o
Just to prove my point...It's exactly what I said => "in my experience likely".
I apologize if my promotion of irc annoys some people but this is the only good source of pascal programmers that I know of and I have a fading hope that some who don’t know about irc would want to come talk there.
AFAIK an "Unofficial FreePascal" Discord server exists - can it be used for the same purpose?
Apologies for my ignorant question, I'm not an IRC user, but what is the actual story? For me, technically there is no big difference between IRC channels and, e.g. Discord channels, but obliviously there is a big background behind this freenode/libera thing.
Yeah, that is probably another point in the favor of the Discord channels. As I said, I'm not an IRC user and don't know it's deficiencies.Apologies for my ignorant question, I'm not an IRC user, but what is the actual story? For me, technically there is no big difference between IRC channels and, e.g. Discord channels, but obliviously there is a big background behind this freenode/libera thing.
Some prefer a richer text environment, for sharing code snippets/examples without having to reply on other gist/paste sites. Being able to use markdown code formatting and go back and edit your code is beneficial to many.
Since an Image can tell more than a thousand words, I quickly made one to show you a little discord workflow.
0. Irc doesn’t require a phone number or email address in order to go there and talk. It’s up to the channel owners whether unregistered users can join a channel. it’s also possible for channel ops to waive registration requirements.To avoid spam-bots/trolls on discord, I do like that things must have an unique ID.
1. Irc lets you choose or create whatever client you want. Discord and others force you to use Their proprietary Spyware client Which collects and monetizes your data as a business model.You can use Discord client or whatever Webbrowser is installed on your system = a more easy way to getting started you can not have with whatever your device is.
2. Irc gives the people who use it more control and can have a chance of a good user interface if you choose/create a good client. Discord has a horrible user interface and doesn’t resize very well. It was impossible to ignore people in discord last time I checked. It informs you everytime they talk.Since I never had that issue (i can very easy mute persons or whole "channels")
3. Irc uses low bandwidth and has no voice chat photos and other nonsense. Discord uses a lot of computer resources and I’ve had it max our my cpu before.Bandwidth depend on how many servers you joined and if you let them auto-update or like i, servers do nothing until i tell.
4. Discord saves offline chats irc requires you to always be online or use a bouncer or other resources that record things you missed including channel logs.Discord helps me to save energy, I do not need 24/7 to have something running to really get "all" messages and what I read or skip depend on me.
I don’t see the point of never missing chatter in a chat channel it’s exhausting to try to catch up. it’s better to use forums for asynchronous communication they are much better organized.
5. Irc doesn’t have voice chat and people can’t show you photos you don’t want to see in the channel everything is done by links to share things like photos or text instead of cluttering channel with them.(De)-Activate image support is done by one easy setting, what I try to say is, when you hate multimedia and want to save bandwidth, just turn it off O:-)
Discord uses a lot of computer resources and I’ve had it max our my cpu before.I just show you my current running Discord CPU usage. Its like 98% less than what you try to tell.
I think it was some bug that made it max out my client. I was clicking around in the voice chats. I’m curious does discord demand a phone number now?Okay, I admit, when I click like crazy fast over all servers I am on, of course the CPU gets more heated up (25% would be max for updating stuff)
Hi KodeZwergIt was fun while I was there, agreed :-*
I remember you in Irc back in 2019. It’s a shame you stopped coming.
Discord wasn’t designed to work on small monitors and doesn’t resize well.I actual can not really comment that since I use at my workstation a very large display and on my little mobile it scale wonderful.
I know you love discord but do you ever wonder why discord provides a free chat client without advertisements? How do they pay all the salaries of employees do you think? It’s a for profit company doing data mining on people who use it.Love would be the wrong word, discord has more comfort to me.
I’m not asking you do give up discord but you could also use irc too whenever you are around.
When using client, a number is a must. Via Webbrowser you can also go anon online but most discord servers only accept registered users (your phone number) and very serious running servers wants you to do 2 step authentication (you need to transmit a code send to your email / phone or other 3rd party authentification app)
I remember when you suggested putting const on all my non changing parameters and it gave me a lot to do.
but of course since the const parameter references the variable that was changed it would have new value.Since ansistrings are already pointers to the text, the param would be a copy of the pointer. So that copy in the param would not change. But the text to which is pointed was changed (it was moved elsewhere in mem).
The idea of using const to avoid copying the record seems good.
Although it seems slightly misleading being able to send a const record in which the fields inside the record can change?. I haven’t tried with records but object fields can change.
I’m curious if there is a way to prevent fields inside objects or records from changing in that situation..
QuoteWhen using client, a number is a must. Via Webbrowser you can also go anon online but most discord servers only accept registered users (your phone number) and very serious running servers wants you to do 2 step authentication (you need to transmit a code send to your email / phone or other 3rd party authentification app)
That sounds horrible, well it only reenforces my data mining theory. I want nothing to do with two factor authentication just to have a chat about pascal. People should not have to buy a cell phone and subscription just to be allowed to chat about pascal or anything else for that matter. When people have your cell phone number they can track everything you do potentially. That is completely unacceptable. Can you even have a cell phone without government ID if not that is even worse. Government being the gate keeper of your being allowed onto social media is a slippery slope which leads nowhere good.
FWIW, I occasionally use Discord for an MMORPG and I've never provided anything other than a special purpose unique disposable email address with which to logon. Certainly no phone number or any other personally identifying information. ISTR they did check the email address could be verified by sending me a link which is fair enough.
procedure bar(c: TFoo); begin c.F1 := 11; // affects the callers instance too / only the pointer is passed in c - it points to the same memory c := TFoo.create; // does not affect the caller // new memory, and pointer goes into c [MEMORY LEAK IN THE LOCAL MEMORY] end; procedure xyz(var c: TFoo); begin c.F1 := 11; // affects the callers instance too // affects the data pointed to // does not affect the pointer in c c := TFoo.create; // does ALSO affect the caller // because "c" is var. So modifying "c" also modifies the caller [THIS MAKES A MEMORY LEAK TO THE INCOMING MEMORY] end;
In the last example it seems it seems like you are detaching the pointer from c and assigning it to a new location possibly leaving the allocated memory it was pointing to stranded. Does modern pascal have a way to prevent stranded memory that can no longer be accessed? It seems like a memory leak could happen.
Also I’m really not sure how classes are different from objects they both seem to allow the bundling of methods and data. I’m assuming that more can be done with classes. I’ve also noticed that sender is tobject .
I’ve also noticed that sender is tobject .TObject is a class.
That keyword "object" is rarely used today (since there are advanced records)....hmmm... I think I use that "rarely old keyword" in every of my classes when I set up custom event handlers...
Ahhh, yes but no-ish...That keyword "object" is rarely used today (since there are advanced records)....hmmm... I think I use that "rarely old keyword" in every of my classes when I set up custom event handlers...
And I could lay my hand in fire that everyone that uses OOP do the same, custom or via https://lazarus-ccr.sourceforge.io/docs/rtl/classes/tnotifyevent.html (https://lazarus-ccr.sourceforge.io/docs/rtl/classes/tnotifyevent.html).
The issue is that "class" and instances thereof are objects. But they are not the type "object". The word object is ambiguous.Agreed :-*
I’m not even sure how to declare or use an advanced record.
Enable the modeswitch AdvancedRecords and then simply add methods to records like you do for class or object types.
Is there a reason to use an advanced record instead of an object? What are the advantages over using object?It's already discussed in detail a while ago. You can search the forum if you want to learn more.
Is there a reason to use an advanced record instead of an object? What are the advantages over using object?In a nutshell, an advanced record does _not_ have _any_ polymorphic calls. which means the compiler knows at compile time, which code will be executed when one of its "method"s is invoked. IOW, there are no indirect or indexed calls to its functions/procedures/methods.
In a nutshell, an advanced record does _not_ have _any_ polymorphic calls. which means the compiler knows at compile time, which code will be executed when one of its "method"s is invoked. IOW, there are no indirect or indexed calls to its functions/procedures/methods.
Thanks for clarifying. That would be useful for more simple things.You're welcome. Advanced records are a good choice when 1. you don't need polymorphism, 2. you don't need them to inherit from something and 3. there is no need for something else (object or class) to inherit from them (since an advanced record cannot be inherited from.) An advanced record is basically a normal record that in addition to listing fields also has a list of functions and procedures that have access (can use) the fields as well as a set of visibility specifiers and possibly a list of properties but, functionally, it pretty much is the same as a record that is restricted to be used by the list of functions, procedures, properties it declares in its body. Other than the syntactic sugar advanced records provide (properties being the "sweetest" part), anything an advanced record can do can be done with a plain record.
Do objects inherit advanced records?No but, _conceptually_ an "object" (not a class) can be thought of as the combination of an advanced record and a virtual method table (a VMT, whose existence is what enables inheritance and polymorphism.)
Besides not allowing virtual methods and inheritance, do the advanced records take less resources than a comparable object with same structure ?Yes, because an advanced record does _not_ have a VMT, therefore it always uses less memory than an "equivalent" object or class. That said, in most cases, the additional memory that is taken by the VMT isn't something that is worth losing any sleep over.
QuoteIn a nutshell, an advanced record does _not_ have _any_ polymorphic calls. which means the compiler knows at compile time, which code will be executed when one of its "method"s is invoked. IOW, there are no indirect or indexed calls to its functions/procedures/methods.
Thanks for clarifying. That would be useful for more simple things.
Do objects inherit advanced records? Besides not allowing virtual methods and inheritance, do the advanced records take less resources than a comparable object with same structure ?
Yes, because an advanced record does _not_ have a VMT, therefore it always uses less memory than an "equivalent" object or class. That said, in most cases, the additional memory that is taken by the VMT isn't something that is worth losing any sleep over.
Old style objects afaik only get a VMT, if they have virtual methods.
Old style objects afaik only get a VMT, if they have virtual methods.Correct. I should have mentioned that.
It’s interesting how function calls take stack space but dynamically allocated variables take heap space maybe because the function calls are considered to be more temporary?The amount of memory used will be the same whether the object is allocated on the stack or the heap because the size of the VMT and the fields that make up the object are independent of where in memory they reside.
I don’t know much about hardware I’m curious about how heap space is implemented compared to stack space? Is stack space RAM?Both, heap and stack are plain, standard RAM. The difference between the two is how they are _managed_. They are managed _very_ differently.
I always thought that there is more memory available on the heap than the stack. Maybe because a “heap” of stuff seems gigantic and a stack seems reasonably small.One of the common differences between a heap and a stack is that, normally, the maximum size of a stack is preset at load time whereas a heap can theoretically grow until there is no more address space available.
I’m going to guess that the assembly language that showed in Lazarus was for the stack because it had jmp commands.
I’m going to guess that the assembly language that showed in Lazarus was for the stack because it had jmp commands. Does assembly for heap use jump commands at all. It seems like access to heap memory is more random than the stack which follows a certain path then backtracks back to where it started.
:o Are you kidding, someone want to learn Assembly?I suggested she (Joanna) learn some Assembly language in order to have a better understanding of how a computer and a compiler works.
:o Are you kidding, someone want to learn Assembly?
< snip >
:o Are you kidding, someone want to learn Assembly?Я изучаю. )))
I just thought of another question.. is assembly language standardized or are there all sorts of different dialects of assembly language?Theres a basic set that works on all CPUs and CPU specific ones. And what code does can be OS dependent.
I just thought of another question.. is assembly language standardized or are there all sorts of different dialects of assembly language?
I just thought of another question.. is assembly language standardized or are there all sorts of different dialects of assembly language?
I just thought of another question.. is assembly language standardized or are there all sorts of different dialects of assembly language?
Coding in assembly should be considered only in extreme cases, by compiler experts or people who wants to squeeze the last tiny bits of performance (often it is more reasonable to revise your algorithm than to resort to assembly for the latter).По большей части я с вами согласен. Но, когда я делал функцию StrToInt на Паскале - компилятор FPC не полностью её оптимизировал. И когда я делал функцию StrToInt на ассемблере, то я получил намного более оптимизированный код. На Паскале, в данное время, мы не сможем получить подобный код. Я бы наверно сказал даже точнее, ни когда не сможем, если только в ассемблере не появятся какие-то новые функции.
I wouldn't go to deep into assembler.Думаю, выбор должен сделать сам программист. :)
I like how posts are not following the "IRC channel" theme. Including myself.Moderator also >:D O:-)
I like how posts are not following the "IRC channel" theme. Including myself.
I have been following the discussion a while. I wonder, is this (https://forum.lazarus.freepascal.org/index.php/topic,61328.0.html) the lRC channel? Yohoo! Hellooohoohoo, I’m on lRC! 58008. Interdimensional Rogue Community (https://en.uncyclopedia.co/wiki/IRC) rulez!That is a rather satirical commentary in irc. In reality it’s not quite so exciting. The majority of accounts in irc are lurkers who never talk. The experience of being in irc depends upon who is participating in the channel. IRC does have a lot of technical people as well as posers who don’t fare so well when asked technical questions. Some channels have trolls join them for the purpose of discrediting and discouraging usage of whatever the channel is about. There are also are professional influencers who come to irc to promote political agendas. I wish more people who do pascal programming would be active in irc.
IRC lacks all this structure. So even though help can be obtained in an IRC like medium, it is not really useful to refer to back to.
when I made the StrToInt function in Pascal, the FPC compiler did not fully optimize it. And when I made the StrToInt function in assembler, I got a much more optimized code. In Pascal, at this time, we will not be able to get such a code.Is there a way to improve the fpc compiler to be as fast for that as assembly language maybe?
As for assembly language being specific to hardware. Does this apply to the assembly language that pops up in Lazarus? If I’m on different computer would that assembly language be different? I don’t suppose that there is a way to make assembly language cross platform?
Irc is a text version of talking or storytelling It’s supposed to be fun, informative and social .real time "chatty" mediums have those characteristics but, for topics that are often centered on problem solving, a static thread of text messages (such as this forum) is usually a much better medium because the progression to the "solution" or best answer isn't simply lost. Here anyone can go back to the beginning or any other message of interest and see the progression towards the current state. For anything that is inherently technical, that is a very desirable characteristic.
As for assembly language being specific to hardware. Does this apply to the assembly language that pops up in Lazarus?Yes but, as @Martin_fr pointed out, the syntax may differ.
If I’m on different computer would that assembly language be different?Yes, it would because the instructions implemented by two different processors will usually differ and sometimes the differences are _very_ large.
I don’t suppose that there is a way to make assembly language cross platform?True assembly language ? ... the answer is NO. That said, C is generally considered a "high level assembler" and it is very portable but C, unlike assembly, does _not_ give the programmer the ability to choose which registers are going to be used to implement an instruction or series of instructions.
Also regarding the problem mentioned about the memory becoming fragmented at runtime how is the memory manager implemented to defragment the heap? Does it slow things down a lot when used?The slowdown will depend on the level of fragmentation and greatly depend on the algorithms used to manage it.
As for assembly language being specific to hardware. Does this apply to the assembly language that pops up in Lazarus? If I’m on different computer would that assembly language be different? I don’t suppose that there is a way to make assembly language cross platform?
I don’t suppose that there is a way to make assembly language cross platform?Я не думаю, что вам стоит настолько глубоко в ассемблер. Потому что это уже не совсем ассемблер.
Ускорить можно, догнать полностью нельзя. Но и ускорением надо заниматься. Но на данное время ни кто не занимается. ARM-ассемблер не оптимизирован практически ни на сколько. Указанные проблемы, указанные на багтрекере, связанные с улучшенной компиляцией кода, на данное время не решаются.
Is there a way to improve the fpc compiler to be as fast for that as assembly language maybe?
real time "chatty" mediums have those characteristics but, for topics that are often centered on problem solving, a static thread of text messages (such as this forum) is usually a much better medium because the progression to the "solution" or best answer isn't simply lost.It isn’t about comparing forums to IRC. of course forums have the advantage of being more organized and people online on different dates and times can have a conversation.
As for the discussion of avoiding memory fragmentation with good memory management, how would that be done besides only allocating variables once. I am in the habit of deallocating things as soon as they are out of view and recreating them if needed. Would I eventually use up all the memory?
As for the discussion of avoiding memory fragmentation with good memory management, how would that be done besides only allocating variables once. I am in the habit of deallocating things as soon as they are out of view and recreating them if needed. Would I eventually use up all the memory?Fragmentation occurs because there is a significant variation in the lifetimes of the various entities allocated in a single large global pool (usually a heap.)
Thanks for the explanation.You're welcome but, the problem is that just about any explanation will be deficient in some way because correct memory management is dependent on the situation. All that can be accurately exposed are the methods but, their correct application depends on, as previously stated, the situation at hand.
I’m not sure how to create pools from inside pascal code or is it set somewhere else?TTBOMK, there is no mechanism in Pascal, including FPC, to create separate/independent pools of memory. In Windows those can be created using HeapCreate, HeapDestroy, VirtualAlloc(Ex), VirtualFree for Heaps and Virtual memory respectively. I know that Linux offers similar functions for Virtual memory management but, I don't know if it offers creation and destruction of heaps.
If the memory does get too fragmented it seems like it could be de fragmented similar to how a disk is defragmented?Yes, it is similar but, not quite the same. The difference is mostly based on the fact that on a disk there is an atomic allocation size (usually the cluster, which in Windows is usually 4K), a file can be made of a linked list of clusters. The file is considered fragmented when the clusters aren't contiguous.
Which I assume would involve copying things to temporary locations and then writing them more compactly?there are lots of problems associated with attempting to defragment memory. It's rarely worth the time or the code.
You should not deal with memory at all, that does do the memory manager for you.I disagree. Good memory management is one of the major factors in writing a program that is resource efficient and responsive. Languages and "systems" (read VMs) that automate memory management for the programmer run into limitations that are a direct result of the "convenience".
You should not deal with memory at all, that does do the memory manager for you.
Thanks for the explanation. I’m not sure how to create pools from inside pascal code or is it set somewhere else? If the memory does get too fragmented it seems like it could be de fragmented similar to how a disk is defragmented? Which I assume would involve copying things to temporary locations and then writing them more compactly?
You can't move that memory, unless you can at the same time update every single of those pointers.That’s interesting I didn’t think about the pointers being fixed addresses.
That’s interesting I didn’t think about the pointers being fixed addresses._maybe_ BUT, you most definitely should _not_ rely on that in any way.
If I allocate and deallocate the same 5 classes whose size doesn’t change, will they stay at the same addresses in memory each time?
Can you give me an example where you was in need to "defragment" memory? Just to be sure, we are now talking about RAM in this IRC channel thread, right?You should not deal with memory at all, that does do the memory manager for you.I disagree. Good memory management is one of the major factors in writing a program that is resource efficient and responsive. Languages and "systems" (read VMs) that automate memory management for the programmer run into limitations that are a direct result of the "convenience".
Can you give me an example where you was in need to "defragment" memory? Just to be sure, we are now talking about RAM in this IRC channel thread, right?Fragmentation is a symptom of, let's call it, poor memory management and, one of the ways that memory is managed poorly is when a program relies heavily on a single pool of memory (usually the default process heap.)
Just to be sure, we are now talking about RAM in this IRC channel thread, right?
Just to be sure, we are now talking about RAM in this IRC channel thread, right?
That’s interesting I didn’t think about the pointers being fixed addresses._maybe_ BUT, you most definitely should _not_ rely on that in any way.
If I allocate and deallocate the same 5 classes whose size doesn’t change, will they stay at the same addresses in memory each time?
Memory fragmentation in today's O/Ss results in memory being wasted.
Can you give me an example where you was in need to "defragment" memory? Just to be sure, we are now talking about RAM in this IRC channel thread, right?
Yes, you are absolutely right. What I meant to emphasize is that in today's O/Ss fragmentation only results in memory being wasted. In previous O/Ss, particularly 16 bit O/Ss, fragmentation could very well result in the program no longer being able to allocate memory. Getting to that point with a 32 bit or 64 bit O/S is a lot harder and unlikely (particularly in a 64 bit O/S.)Memory fragmentation in today's O/Ss results in memory being wasted.
Only in today's OS? I though it was a timeless phenomenon, that having memory in a state in which it can't be used meant it was wasted....
Actually, there is a way in FPC (also in Delphi) to write your own heap manager. That is the way the fastmm, heaptrc and cmem units were written.I’m not sure how to create pools from inside pascal code or is it set somewhere else?TTBOMK, there is no mechanism in Pascal, including FPC, to create separate/independent pools of memory. In Windows those can be created using HeapCreate, HeapDestroy, VirtualAlloc(Ex), VirtualFree for Heaps and Virtual memory respectively. I know that Linux offers similar functions for Virtual memory management but, I don't know if it offers creation and destruction of heaps.
With a recent CPU's incorporating VM support hardware and capable of address linearization, the task should be not very different than disk/cluster de-fragmentation. To what extent this is implemented in the operating system and whether this simply pushes the problem to another level is a separate matter. There are known allocation patterns which makes Windows to extend the process commit size beyond the limits.If the memory does get too fragmented it seems like it could be de fragmented similar to how a disk is defragmented?Yes, it is similar but, not quite the same. The difference is mostly based on the fact that on a disk there is an atomic allocation size (usually the cluster, which in Windows is usually 4K), a file can be made of a linked list of clusters. The file is considered fragmented when the clusters aren't contiguous.
In memory, particularly heaps, the problem is different. Free heap blocks, unlike a disk cluster, can vary greatly in size which causes problems when attempting to reuse them: either they may be too small, therefore unusable, or too large which, if used for a smaller structure, means some of the memory is simply wasted.
Actually, there is a way in FPC (also in Delphi) to write your own heap manager.writing your own heap manager is a very different thing than being able to create multiple heaps which is what I was referring to. As I stated previously, TTBOMK, FPC does not offer that capability.
With a recent CPU's incorporating VM support hardware and capable of address linearization, the task should be not very different than disk/cluster de-fragmentation.VM support or otherwise, it is very different. When the heap receives a request for "n" kilobytes, say for the sake of argument 12kb, a heap _must_ provide a _contiguous_ 12kb whereas a request for the same amount of storage on disk can be filled with 3 clusters of 4kb each. A heap does _not_ have that luxury.
With a recent CPU's incorporating VM support hardware and capable of address linearization, the task should be not very different than disk/cluster de-fragmentation. To what extent this is implemented in the operating system and whether this simply pushes the problem to another level is a separate matter. There are known allocation patterns which makes Windows to extend the process commit size beyond the limits.If the memory does get too fragmented it seems like it could be de fragmented similar to how a disk is defragmented?Yes, it is similar but, not quite the same. The difference is mostly based on the fact that on a disk there is an atomic allocation size (usually the cluster, which in Windows is usually 4K), a file can be made of a linked list of clusters. The file is considered fragmented when the clusters aren't contiguous.
In memory, particularly heaps, the problem is different. Free heap blocks, unlike a disk cluster, can vary greatly in size which causes problems when attempting to reuse them: either they may be too small, therefore unusable, or too large which, if used for a smaller structure, means some of the memory is simply wasted.
You can't defragment the virtual address space as that would need to change the pointers that are stored e.g. in the stack or where ever. You can defragment your own heap only with deallocated areas by combining them again or whatever depending on your heap management algorithm.My point was that, theoretically by using MMU, the fragmentation could be avoided by redirecting/merging physical RAM pages in the address translation table (which could be seen as additional redirection, like handles in GlobalLock). But since the MMU is managed exclusively by the operating system, this is almost impractical unless one is working with the bare metal.
The idea of using handles that point to pointers to memory locations seems like a good idea.It's one of those ideas that seems good at the beginning but, time reveals it's not such a "good idea" in the long run. The problem is, the program cannot access any memory block without first locking the handle which is what returns a pointer to the memory block. Locking the handle has the effect of telling the O/S that, that memory block cannot be moved. Without the program's cooperation, the O/S will usually not be able to achieve a reasonably decent level of defragmentation. With program cooperation, the O/S should be able to defragment the memory BUT, the problem then becomes the amount of time the defragmentation may take and, timing it in such a way that it doesn't significantly affect its smooth operation.
It seems like being able to defragment memory is very important for programs expected to run for a long time without stopping.What's really important is to _avoid_ fragmentation to an extent where it becomes a problem. Once it has become a problem, there is no solution that is free of potentially very undesirable consequences.
The logic of defrafmenting memory seems like it would be fairly simple kind of like defragmenting people in a theatre by making them all scoot over and remove gapsIt's very different than having people scoot over to remove gaps because, in the case of people in a theater there isn't "anyone" keeping track and _depending_ on where each person is seated (i.e, having a pointer to the person that needs to be updated if and when the person moves.)
The idea of using handles that point to pointers to memory locations seems like a good idea. It seems like being able to defragment memory is very important for programs expected to run for a long time without stopping.
The logic of defrafmenting memory seems like it would be fairly simple kind of like defragmenting people in a theatre by making them all scoot over and remove gaps
You can't defragment the virtual address space as that would need to change the pointers that are stored e.g. in the stack or where ever. You can defragment your own heap only with deallocated areas by combining them again or whatever depending on your heap management algorithm.My point was that, theoretically by using MMU, the fragmentation could be avoided by redirecting/merging physical RAM pages in the address translation table (which could be seen as additional redirection, like handles in GlobalLock). But since the MMU is managed exclusively by the operating system, this is almost impractical unless one is working with the bare metal.
Description of problem: At the moment the aarch64 kernel builds of RHEL8 assume a 64kB pagesize, which works fine most of the time. However when trying to run in a virtualized environment on Apple M1 devices via Parallels Desktop it is not possible to boot RHEL8 because the M1 chips only support 4kB & 16kB pagesizes. Ubuntu and Debian are compatible with Parallels on these devices, so it should be possible for RHEL as well.
The idea of using handles that point to pointers to memory locations seems like a good idea.It's one of those ideas that seems good at the beginning but, time reveals it's not such a "good idea" in the long run. The problem is, the program cannot access any memory block without first locking the handle which is what returns a pointer to the memory block. Locking the handle has the effect of telling the O/S that, that memory block cannot be moved. Without the program's cooperation, the O/S will usually not be able to achieve a reasonably decent level of defragmentation. With program cooperation, the O/S should be able to defragment the memory BUT, the problem then becomes the amount of time the defragmentation may take and, timing it in such a way that it doesn't significantly affect its smooth operation.It seems like being able to defragment memory is very important for programs expected to run for a long time without stopping.What's really important is to _avoid_ fragmentation to an extent where it becomes a problem. Once it has become a problem, there is no solution that is free of potentially very undesirable consequences.The logic of defrafmenting memory seems like it would be fairly simple kind of like defragmenting people in a theatre by making them all scoot over and remove gapsIt's very different than having people scoot over to remove gaps because, in the case of people in a theater there isn't "anyone" keeping track and _depending_ on where each person is seated (i.e, having a pointer to the person that needs to be updated if and when the person moves.)
It's usually quite easy to _avoid_ fragmentation, it only requires a little bit of upfront thinking about the program's design.
The idea of using handles that point to pointers to memory locations seems like a good idea. It seems like being able to defragment memory is very important for programs expected to run for a long time without stopping.It is indeed important.
The logic of defrafmenting memory seems like it would be fairly simple kind of like defragmenting people in a theatre by making them all scoot over and remove gapsYes, but such a 'house keeping' is a time consuming and introduces unpredictability with regard to the response time, etc. It is better simply to avoid fragmentation instead of dealing with it.
The idea of using handles that point to pointers to memory locations seems like a good idea. It seems like being able to defragment memory is very important for programs expected to run for a long time without stopping.
The logic of defrafmenting memory seems like it would be fairly simple kind of like defragmenting people in a theatre by making them all scoot over and remove gaps
But at a higher level, how does this translate into use by by the data structures and current live stack frames that are using the pointers?
You move memory blocks around in a processor level multi-threaded application everything using those blocks is going to crash.
The handles would then have to essentially be indirect pointers (so regular code is not getting actual pointers any more). Even with them being indirect, there would need to be synchronization to make sure sure nothing is using a live pointer. So something like a stop the world garbage collection sweep. Then on top of that, the handles are now essentially data structures, and what is going to defragment them?
...
You can't defragment the virtual address space as that would need to change the pointers that are stored e.g. in the stack or where ever. You can defragment your own heap only with deallocated areas by combining them again or whatever depending on your heap management algorithm.My point was that, theoretically by using MMU, the fragmentation could be avoided by redirecting/merging physical RAM pages in the address translation table (which could be seen as additional redirection, like handles in GlobalLock). But since the MMU is managed exclusively by the operating system, this is almost impractical unless one is working with the bare metal.
Another idea which has probably already been tried is how about marking addresses with their size as reusable when finished with them and then when something new is needed just reuse existing piece of memory that is the same size? This might be ok when there is not too much size variation..That's what the Windows Heap manager does and it imposes some overhead (which is always undesirable.) The heap manager keeps track of a linked list of freed blocks sorted by size along with 4 pointers into the linked list where each guarantees the size of a free block being greater than or equal to some value (that's how Win9x did it - see Matt Pietrek's Windows Programming Secrets - the management algorithms have been improved in the NT branch of Windows but, the management concepts are still the same.)
I have no idea how this would be implemented though.
I used to think that freeing things as soon as they weren’t needed would be more efficient for using less memory but after this discussion I’m no longer so sureActually, the majority of the problems come into existence when allocations and deallocations are mixed. A reasonably decent solution is, create a heap, put all the data you need in there, don't delete/free anything, once you don't need the data, simply destroy the heap. That way allocations will be fast because there are no chains of "free space" to search and, if the heap is dedicated to a single thread, it can be told not to use a synchronization object.
Memory indeed is a complex issue. I’m not sure what the history of computer design was that led to the memory becoming so easy to fragment. Stack memory seems so elegant in comparison but that won’t work for randomly allocated/ deallocated things.Yes, it is, without a doubt it can be quite complicated.
Another idea which has probably already been tried is how about marking addresses with their size as reusable when finished with them and then when something new is needed just reuse existing piece of memory that is the same size? This might be ok when there is not too much size variation..The existing heap manager is doing a decent "pooling" for you, at least for the small chunks. It is really a quite good at that (I had mentioned it before (https://forum.lazarus.freepascal.org/index.php/topic,61328.msg463126.html#msg463126)). But if you're writing a high-availability application it requires very, very careful planning.
I have no idea how this would be implemented though.
I used to think that freeing things as soon as they weren’t needed would be more efficient for using less memory but after this discussion I’m no longer so sureThat is always a good approach, and it has also additional benefits (https://en.wikipedia.org/wiki/Resource_acquisition_is_initialization#Benefits) e.g. reduces the possibility of leaks, deadlocks, etc.
I do tend to use classes a lot some of which contain strings. I am curious if I change the length of a string stored in the field of a class does that change the amount of memory being used? I think shortstring is limited to 255 chars but string has no fixed length ,so how much memory would be used? Just enough to store it in its current length? Supposed you have a a tmemo and paste a lot of text into it? What happens With memory? Does pasting text allocate memory? Or suppose you create a class containing a tmemo and retrieve the text from an inifile. The class needs less memory before the text is loaded? I’m curious how it all works. If you create another class before loading text to memo it seems like the memory Pertaining to different classes could be intertwined.Short strings (those with the square brackets [] at the end) are fully contained into the declared variable/record/class. From the memory perspective, string[N] can be viewed as array[0..N] of char with zero index being used as the current string length. They are just handled a bit differently than arrays by the compiler (you can concatenate them with + for example). On the other hand, strings declared without square brackets are actually pointers to an internal structure in heap, which holds the contents together with the code-page, current length, reference counter. In the trivial case when the string is empty ('') the pointer is just Nil. They are "managed", i.e. the compiler internally allocates/reallocates/de-allocates them according to the operations applied. They have copy-on-write (https://en.wikipedia.org/wiki/Copy-on-write) semantics.
I’ve never done a multithreaded application. What are the circumstances which require multiple threads is it for being able to respond to different events while something else is working?Multithreading is a vast subject which has also close relationships with the memory management, but IMO it shouldn't be involved into the discussion, it will be too much for now.
I vaguely remember a command that could be put into a loop to respond to messages . I can’t remember what it was...
But since LCL is for UI, it is not expected the application to work for an indefinite amount of time i.e. it will be closed, restarted, etc.While that might be true in most cases I think that gui programs should be designed to run indefinitely. Restarting things is annoying and sometimes loses data.
That Is interesting how pascal handles strings of indetermined length as a pointer to memory in such a way as to keep allocating more memory as the string is appended to. I’ve heard that other languages are not so smart with string management and have overflows?Not so easily as some measures were taken already to mitigate the effect. I already pointed out that the current FPC heap manager do pooling and as Marc noted, the strings allocation is made accordingly.
It also seems like a program with a lot of strings that come and go could get easily fragmented in memory.
I did not mean that they should be restarted every hour or two, rather only when necessary and it can be done in a way that is not so obvious, e.g. for maintenance, for updating, for improving the service, archiving data, you name it.QuoteBut since LCL is for UI, it is not expected the application to work for an indefinite amount of time i.e. it will be closed, restarted, etc.While that might be true in most cases I think that gui programs should be designed to run indefinitely. Restarting things is annoying and sometimes loses data.
Strings are allocated with some extra room, so adding one character won't require a new allocation.I’m curious if shortstring reserves a full 255 bytes even if what is being stored is only 3 letter string.
Strings are allocated with some extra room, so adding one character won't require a new allocation.I’m curious if shortstring reserves a full 255 bytes even if what is being stored is only 3 letter string.
I suppose this is why the ability to define shorter strings like string [5] exists.
Also I wonder is there are any differences in the way unicode strings are stored in memory compared to ascii Strings.
Strings are allocated with some extra room, so adding one character won't require a new allocation.I’m curious if shortstring reserves a full 255 bytes even if what is being stored is only 3 letter string.
I suppose this is why the ability to define shorter strings like string [5] exists.
Also I wonder is there are any differences in the way unicode strings are stored in memory compared to ascii Strings.
I’m curious if shortstring reserves a full 255 bytes even if what is being stored is only 3 letter string.
I suppose this is why the ability to define shorter strings like string [5] exists.
Also I wonder is there are any differences in the way unicode strings are stored in memory compared to ascii Strings.
A Short string is always going to be 256 bytes.
A Short string is always going to be 256 bytes.
Not fully correct.
shortstring[10];
https://wiki.freepascal.org/Shortstring
A Short string is always going to be 256 bytes.
I still fail to grasp why for simple questions like these it seems you want or expect others to look up the answers for you, when you could have just as easily looked them up yourself.
Interesting. But one can't doQuoteshortstring[10];
This only works when string is shortstring?
Its length is defined as: ShortString = String[255];
I still fail to grasp why for simple questions like these it seems you want or expect others to look up the answers for you, when you could have just as easily looked them up yourself.
Interesting. But one can't doQuoteshortstring[10];
This only works when string is shortstring?
And https://wiki.freepascal.org/Shortstring which gives the answer:QuoteIts length is defined as: ShortString = String[255];
Shortstring already has a length set. It is a type defined as "String[255]"
So, no you can't do "shortstring[10]"
Something about a the woods and trees... Something about "in plain sight"... ;)
The thing is, one can still store UTF-8 in short strings, so the size limit can be confusing.
Yeah.... So, does tkSString refer to short string or sized string?
And yes, I'm being a bit pedantic here...
Not sure where tkSString comes from (not bothered to search if it mentioned in any of the docs :P ). Sounds like compile sources.
QuoteBecause they might be using some program they like that is written in Lazarus or free pascal, and they are trying to work with the maintainers of said program (or some other pascal programmer that could help). They might not have the kind of attitudes of free pascal you want. However, they are trying to improve an existing tool they find a lot of value in.If that is the case they need to find the people who actually created the application before complaining about it.
Actually we have had trolls/{people who think we are their servants} come to both platforms with some program written in pascal/ delphi repeatedly demanding that we fix it right away. This is just another style of trolling whether it’s intentional or not. I’m sure everyone remembers the troll demanding to compile a program with windows dependencies in linux not so long ago.
Fake help requests often ensnare what few good people are still active and wastes their time and frustrates them, making them less likely to try to help in future. We have had a troll that kept coming to irc with different accounts asking the same exact question should he use oop. No matter what people said he would manage to turn it into an argument, filling the chat with drivel and annoying people who didn’t understand that he was a troll.
There is maybe the scenerio where someone Who hates Pascal has been hired to translate legacy pascal code to another language. We have no obligation to help someone who is being paid to get rid of pascal, it’s in our best interests to go in the opposite direction. People who hate pascal poison the chat with their negativity. We have no obligations to be punching bags for everyone who is unhappy that pascal still exists.
Another possibility is someone has some fancy old code they want to redo using pascal thats great but this also means that they need to know pascal language!!
I often try to help people who don’t know pascal by giving them link to good online book on pascal. Not a single one has ever thanked me nor read the book. Do you want to know why? Because they are not interested in using pascal, they are there to troll.
Did I by chance make a comment about killing someone who would hurt my kids? Someone possibly hurting them in ways we have had off topic discussions about maybe concerning forced vaccinations and removal of my kids from school?Yes that’s right your plan was to send your kids to school and then kill the people at the school if they vaccinated the kids when you weren’t there. I didn’t see the logic of such a plan and suggested home schooling.
You banned my uncle right after he registered to get in the channel. He is still learning Pascal without your IRC channel.Who was your uncle? It is Interesting that you suddenly have an “uncle” interested in pascal.
There is only one other thing I am as passionate about as I am about programming and that is, soccer. Between FPC, the Lazarus IDE and the world cup... it doesn't get any better than this :)I wish we had more people like you in irc instead of lurkers and trolls but if you are too busy I guess it can’t be helped.
Ban is really the last I personal would do and I am moderator not just on 1 big Pascal related discord server :-XAfter awhile you will realize that trolls can’t help themselves and can always come back. Banning only slows them down a little ...
18+ (xxx content) or racism lead to instant ban when I have duty, that I will never allow. >:D
Having small fights like trolls (small kids) are doing, well "timeout" or "kick" to make them calm if they not listen to us moderators. O:-)
You know... I have had my IRC client connected for years and years. Maybe I shall just see what lies in the logs?
After I talked Bogen85 into returning to irc he enlivened the fpc channel quite a bit.
Bogen85 if you had not deleted my messages in your temper tantrum you would have seen my explanation of who
If you still believe that someone else is a troll (you know who I am referring to), then please, put him on trial here in the forum
Notes about the moderation aboveBogen85 if you had not deleted my messages in your temper tantrum you would have seen my explanation of who
This post contained reference (including background on employment) about several people (but particular one person) from the IRC channel (identified by their nicks). One person in question contacted me, to have their data removed.
The post lined out some other participants on the IRC channel may have influenced opinions of others. (Who told lies to whom, who may have spied on whom, ...).
From what I can conclude it was a response to this.If you still believe that someone else is a troll (you know who I am referring to), then please, put him on trial here in the forum
As that person however does not wish to be "put on trial" here, and the information is otherwise only relevant (and also only meaningful) to the above quoted parties, I decided to remove the information as requested.