* * *

Author Topic: RTL: FileLockRegion ()  (Read 348 times)

joho

  • New member
  • *
  • Posts: 47
  • Joaquim Homrighausen
    • ~/JoHo
RTL: FileLockRegion ()
« on: September 04, 2017, 11:50:07 am »
Is there any way to do regional (or "byte count") file locking with FP? If not, will there be?

These translate to LockFile () in Windows and DosSetFileLocks () in OS/2. For DOS, I believe it's function $5C.

(I'm not talking about file locking by using different open modes, I'm talking about locking a section of a file)

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5644
Re: RTL: FileLockRegion ()
« Reply #1 on: September 04, 2017, 01:54:05 pm »
Not abstracted, should go via OS specific apis.

There are locking possibilities on Linux, but IIRC they were not very practical (fpflock for whole file, and fcntl F_SETLK locks for byte ranges). But that is just heresay, never did it myself. 

Thaddy

  • Hero Member
  • *****
  • Posts: 4439
Re: RTL: FileLockRegion ()
« Reply #2 on: September 04, 2017, 04:17:30 pm »
You ask a lot of questions about features that even an advanced programmer never, if ever, needs.
Since you do so, I expect you can solve any further programming yourself and just explain the basics:
- What you are asking for is technically a window on the data. Look for a windowed stream (there are many)
- On a low level you can achieve this under linux with https://www.freepascal.org/docs-html/3.0.0/rtl/baseunix/fpmmap.html and under Windows similarly with https://msdn.microsoft.com/en-us/library/windows/desktop/aa366556(v=vs.85).aspx 

There's no point in having this unified, because, as I explained, it is not often necessary and when you need it, do it on the OS level. (As Marco suggested)
And I really wonder if you need it: properly written concurrency - in user space - does not need it!

From your questions, I deduct you are not a Noob (at all) . You require some brushing up on proper software design, though.

But there you go. Should be enough. O:-)
« Last Edit: September 04, 2017, 04:28:10 pm by Thaddy »
"Logically, no number of positive outcomes at the level of experimental testing can confirm a scientific theory, but a single counterexample is logically decisive."

joho

  • New member
  • *
  • Posts: 47
  • Joaquim Homrighausen
    • ~/JoHo
Re: RTL: FileLockRegion ()
« Reply #3 on: September 04, 2017, 04:32:35 pm »
Thank you both for responding.

I'm not trying to point out flaws or faults in FP, quite the contrary. I'm asking questions mainly related to porting a big application from Borland Pascal / Virtual Pascal to Free Pascal. In that process (or attempted process), I run across quite a few question marks. I can of course just keep my mouth shut and go on my merry way and continue doing "my own I/O" (for example). But if the tables were turned, I for one would appreciate questions of a different nature, even if they require my explaining :)

There are many ways of doing most things, and I think that learning as many of them as possible is often a good idea, if for nothing else then to avoid being stuck in the same frame of mind. "Proper software design" is an interesting subject, and I'm guessing there are more theories about that than there are so-called programmers.

I don't know what an "advanced programmer" is, but I can't see how disqualifying someone else's needs just because they don't agree with your own opinions is a very fruitful direction to take. When I started coding (1983), there very few "best practice" things around ... so, you make up your own best practice. I'm glad to see things evolve.

Most of the time, I think you'll find that my questions are actually meant to ask people who have more knowledge of FP than I what "Best practice" (in a FP context) is. That, at least, is my only intention.

If I stepped on someone's toes, then I apologize.

Thaddy

  • Hero Member
  • *****
  • Posts: 4439
Re: RTL: FileLockRegion ()
« Reply #4 on: September 04, 2017, 04:45:11 pm »
I'm not trying to point out flaws or faults in FP, quite the contrary. I'm asking questions mainly related to porting a big application from Borland Pascal / Virtual Pascal to Free Pascal.
Virtual Pascal is an issue, then, because Borland Pascal translates almost flawless. Virtual Pascal is also not maintained... (doesn't even work anymore on some platforms) and was programmed in C.
Quote
There are many ways of doing most things, and I think that learning as many of them as possible is often a good idea, if for nothing else then to avoid being stuck in the same frame of mind. "Proper software design" is an interesting subject, and I'm guessing there are more theories about that than there are so-called programmers.
Studying computer science may be a good idea after all 8-)
Quote
I don't know what an "advanced programmer" is, but I can't see how disqualifying someone else's needs just because they don't agree with your own opinions is a very fruitful direction to take. When I started coding (1983), there very few "best practice" things around ... so, you make up your own best practice. I'm glad to see things evolve.
Marco + me equals 110+ years with 75+years in programming.. (sorry Marco, I get the balance 8-) )
Quote
Most of the time, I think you'll find that my questions are actually meant to ask people who have more knowledge of FP than I what "Best practice" (in a FP context) is. That, at least, is my only intention.
Best practice is using the new language features too.... These were not added for dinosaurs..
Quote
If I stepped on someone's toes, then I apologize.
You didn't. Actually Marco fixed one of the issues. This one is not going to happen. 8-) (I guess)
« Last Edit: September 04, 2017, 04:50:26 pm by Thaddy »
"Logically, no number of positive outcomes at the level of experimental testing can confirm a scientific theory, but a single counterexample is logically decisive."

joho

  • New member
  • *
  • Posts: 47
  • Joaquim Homrighausen
    • ~/JoHo
Re: RTL: FileLockRegion ()
« Reply #5 on: September 04, 2017, 04:57:02 pm »
Well then, I'm glad I'm in such good and fine company, being surrounded by pros is great!

I think one of the biggest issues is that in the beginning, a lot of RTLs sucked. So ended up writing "libraries" of int 21 translations (and others) to get handled based I/O so it "sort of" looked like C. And then I continued doing that. When I ported it to VP, I ported the libraries too (for OS/2), and that worked out well. Now I'm trying to do it the other way around and "only use standard FP stuff", which is proving to be a test.

But I'm sure I'll get it at some point.

Thanks.

cpicanco

  • Sr. Member
  • ****
  • Posts: 364
    • My Portfolio
Re: RTL: FileLockRegion ()
« Reply #6 on: September 04, 2017, 06:23:53 pm »
Hi joho, please, just ignore the grumpy Thaddy. He seems to like making people uncorfortable in this forum. You will save a lot of time for yourself. Also : PLEASE learn form the wise Thaddy, he is very experienced though grumpy. What he was trying to say is that you can improve your skills for you (complicated) subject domain (and so saving money and time) by informing yourself (if you haven't yet) on design patterns and overall software archteture on this domain. Otherwise, you can trust in his (and Marco) consultancy and try the mentioned known approach.

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5644
Re: RTL: FileLockRegion ()
« Reply #7 on: September 04, 2017, 06:32:42 pm »
You ask a lot of questions about features that even an advanced programmer never, if ever, needs.

It might be an open door, but my guess is that Joho's application is quite significant ;)

Still, the problem is a bit that things like this (like locking, which is typically used for multi user flat file dbs) are something from a dos era. However some old systems have multi instances designed in, and there is no simple way about it. However since these were mostly already out of vogue before FPC really began to rise, and specially before 2005 the accent was heavily on Linux which has less rich APIs then e.g. Windows or OS/2, they were never abstracted. Simply because nobody had practical, multiplatform knowledge about them.

Basically it is simply a matter of having a simple unit with some ifdefs for the targets you support. If you can get it work reliably, we could even fold it into FPC at some point

« Last Edit: September 04, 2017, 06:36:52 pm by marcov »

joho

  • New member
  • *
  • Posts: 47
  • Joaquim Homrighausen
    • ~/JoHo
Re: RTL: FileLockRegion ()
« Reply #8 on: September 04, 2017, 07:41:10 pm »
You ask a lot of questions about features that even an advanced programmer never, if ever, needs.

It might be an open door, but my guess is that Joho's application is quite significant ;)

Still, the problem is a bit that things like this (like locking, which is typically used for multi user flat file dbs) are something from a dos era. However some old systems have multi instances designed in, and there is no simple way about it. However since these were mostly already out of vogue before FPC really began to rise, and specially before 2005 the accent was heavily on Linux which has less rich APIs then e.g. Windows or OS/2, they were never abstracted. Simply because nobody had practical, multiplatform knowledge about them.

Basically it is simply a matter of having a simple unit with some ifdefs for the targets you support. If you can get it work reliably, we could even fold it into FPC at some point

Well, if I manage to port this beast to FP, and if there's anything useful I can give back to FP, I will of course be happy to do so :) I will try to emulate what I need from functionality already available in FP. For the rest, I will either do dummy code for now and deal with it later, or sit down and get them working as needed with native code. Regardless, I appreciate being able to discuss these things with Pros and people who know FP far better than I.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus