ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
are there any disadvantages (e.g. in terms of performance or otherwise) in using system calls, as opposed to using direct bindings made for a programming language?
In particular, I have in mind the management of extended attributes (xattr).
For most things, you can find useful "prior art" that you can use in your program. For example, a quick Google on "how to use extended attributes in C++" pointed me, say, to http://www.lesbonscomptes.com/pxattr/.
No matter what it is that you're doing, someone usually has done it before, and has "wrapped up the dirty messy smelly guts of how to do it" in a nice piece of fish-paper. It's well worth looking for such things.
"Performance" and so-forth is going to be irrelevant, because "whatever-it-is that the routine actually does" will very quickly zero-in on "the necessary system call(s), and nothing more." You're simply looking for convenience, robustness, the ability to leverage someone else's instead of your own, and to stay as much as possible within the paradigm of your particular programming language.
What language are you using and what platform(s) is the code supposed to run on?
The Language is FreePascal, and the program is supposed to run on Linux.
Quote:
For most things, you can find useful "prior art" that you can use in your program. For example, a quick Google on "how to use extended attributes in C++" pointed me, say, to http://www.lesbonscomptes.com/pxattr/.
No matter what it is that you're doing, someone usually has done it before, and has "wrapped up the dirty messy smelly guts of how to do it" in a nice piece of fish-paper. It's well worth looking for such things.
Yes, I know. I have already asked for previous solutions on the FreePascal/Lazarus forum. All I got is the advice of using the Linux system call.
Actually I was looking for a direct binding for the Language, assuming that it would be faster. Functionally, the system call should be good enough, in the sense that it works.
My question on this forum was precisely whether I should be satisfied with using the system call, or twhether I should keep looking for a binding, although in the case of FreePascal non previous bindings are available.
In case the "system call" solution is good enough (without too much overhead on performance), then I would stop searching for an alternative and simply use it.
Quote:
"Performance" and so-forth is going to be irrelevant, because "whatever-it-is that the routine actually does" will very quickly zero-in on "the necessary system call(s), and nothing more."
My assumption (which may be wrong, course) was that the system call itself could entail some delay, and that a binding that bypasses the system call might be faster. Is that so?
No, I think that the suggestion is that you should either obtain or construct a module within your program whose interface represents, well, "what does it do?" (And whose implementation, then, encapsulates: "how does one do it?")
This module will carry out the system-calls to do its work. But it prevents those system-calls (hence: "system-specific how-to-do-its") from proliferating throughout the rest of the program's source code.
Hence, if the program ever needed to be ported, only that one module would have to change. (And, there would be only one place in the program where someone would have to be staring at a manual concerning those system-calls while trying to add a new feature or to chase down a bug.)
"Performance" is a non-issue here. "Maintainability," however, is a ruling concern, and this strategy will do a lot to preserve that.
No need to avoid system calls but don't use them if you don't need to.
If your language has constructs or libraries that do what you want then it's probably advisable to use them.
Please give a few examples, what system calls you intend to 'use directly'.
I must say am not very expert of these things, that's why I am asking you guys.
What I had in mind was having a direct binding for the setxattr and getxattr commands, from withing the programming language, accessing directly the relevant library. As pointed out, the same end result can be easily accomplished via system calls, which are supported by most programming languages.
My doubt was only about the possible disadvantages.
BTW what would be the relevant library for those two commands?
I must say am not very expert of these things, that's why I am asking you guys.
What I had in mind was having a direct binding for the setxattr and getxattr commands, from within the programming language, accessing directly the relevant library. As pointed out, the same end result can be easily accomplished via system calls, which are supported by most programming languages.
My doubt was only about the possible disadvantages.
BTW what would be the relevant library for those two commands?
What I had in mind was having a direct binding for the setxattr and getxattr commands, from within the programming language, accessing directly the relevant library. As pointed out, the same end result can be easily accomplished via system calls, which are supported by most programming languages.
My doubt was only about the possible disadvantages.
BTW what would be the relevant library for those two commands?
Thanks
System calls will be faster than using library functions, which I think is what you mean by "direct binding". Your "binding" will just be making the system calls anyway, but there will be added overhead for the function calls and whatever else the functions might do, such as error checking.
If you are only planning to run on Linux, then using system calls shouldn't result in much portability problems except in rare cases.
However, the performance gains will be very small, and most programmers wouldn't bother with making syscalls because for one thing, many programmers don't understand the OS at that level and for another thing because it is harder. Other people might cite portability and maintainability as disadvantages, and its true somewhat, but there is always debate.
In your case, I say go ahead with the syscalls if you can do it. Your performance will not suffer, in fact, it will be marginally better, but probably not noticeable. If you plan to run your software on something like, say, OSX, then you might run into problems.
My Debian 6 is a bit oldish, so I cannot tell what setxattr/getxattr is good for; but I'm quite sure that using them (either via function-call or INT 0x80) will make your program platform-dependent.
My Debian 6 is a bit oldish, so I cannot tell what setxattr/getxattr is good for; but I'm quite sure that using them (either via function-call or INT 0x80) will make your program platform-dependent.
Also filesystem dependent. Not all file systems support extended attributes and/or may be disabled (hence the "extended" part).
In your case, I say go ahead with the syscalls if you can do it. Your performance will not suffer, in fact, it will be marginally better, but probably not noticeable. If you plan to run your software on something like, say, OSX, then you might run into problems.
... whereas I would respectfully dissent, and say to the OP: "if you find a saddle, ride in it, instead of trying to hang-on to the back of the horse." System calls are really designed to be the lowest level interface. There's a lot of stuff that is "ordinarily needed" that has already been built on-top of that layer, in the form of standard system libraries ... both those that are included with the language and those that are not. To me, it's senseless to reinvent any wheel at all. There's no "up-side" to doing it, it takes many hundreds of thousands of microseconds to add-up to the blink of an eye, and there could be a "down-side," therefore ... "why (bother)?"
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.