Programming Leftovers
-
Dlsym() 3 C Function
“Linux has come up with many of its unique functions to perform routine tasks. The dlsym() function is one of them. The dlsym() function goal is to find the address of a defined symbol specified in a DLL (Dynamic Link Library) that has been made accessible via a dlopen() function call. After loading the dynamic shared object (common link library) file indicated by the null-terminated string filename, the function dlopen() outputs an anonymous “connection” for the loaded object. The named symbol is looked up in the dynamic link library (DLL) that has been fetched by the dlopen() method. In this article, we will talk about the use of dlsym().
If the desired symbol is not present in that DLL, the dependent DLLs of that DLL will be searched for it, after by any dependencies of those, and so on in a breadth-first fashion until the desired symbol is found or all the DLLs have been searched for this purpose. Although the sequence in which dependent DLLs at the same level are searched is undetermined, this search order determines how duplication symbols in distinct DLLs will be identified. Be aware that unloaded dependent dynamic libraries won’t be loaded as a consequence of a dlsym() search for dependent DLLs. Only the DLLs that were loaded as a component of the dlopen() call’s dependent DLLs will be scanned.”
-
Bzero 3 C Function
“The basic memory structure of a computer may be easily accessed by programmers or users in C or other programming languages. They can interact and perform numerous commands on memory using registers and other tools. Memory management is thus one of the primary functions of the C programming language. Thus, the typical operation applied in many scenarios involved zeroing out the region of computer memory. Dynamic memory should occasionally be filled with zeros to purge garbage entries.
Some structs often need to have their multiple bit-mask values explicitly replaced with zeros before their members are initialized. For this, the C language came up with the bzero 3 functions to be utilized in the program. Thus, we have decided to implement the use of the bzero 3 C function in our C program. Let’s get started.”
-
Counting Sort Complexity
Counting sort is best illustrated with the sorting of integers. In C/C++ and Java, the characters are integers and can be sorted in the way the integers are sorted.
-
Epoll 7 C Function
The C language is a very vast language when it comes to the use of different technologies or APIs. It is also very usable when we want to use the socket programming. Just like this, it comes up with the epoll 7 functions. Poll(2) and the epoll API both observe the various document descriptors to determine whether I/O is feasible on every one of them. The epoll API extends very well with the great numbers of monitored document descriptors and may be used as being either a level-prompted or edge-prompted gateway.
The epoll entity, an in-kernel information model that may be seen from the user-space as a wrapper for two sets, serves as the foundational idea of the epoll API. Within this guide, we’ll discuss the use of the epoll function in the C language.
-
Comparing strtod with from_chars (GCC 12) – Daniel Lemire's blog
A reader (Richard Ebeling) invited me to revisit an older blog post: Parsing floats in C++: benchmarking strtod vs. from_chars. Back then I reported that switching from strtod to from_chars in C++ to parse numbers could lead to a speed increase (by 20%). The code is much the same, we go from…
-
Rakudo compiler, Release #157 (2022.07) - Rakudo Compiler for Raku Programming Language
On behalf of the Rakudo development team, I’m very happy to announce the July 2022 release of Rakudo #157. Rakudo is an implementation of the Raku1 language.
-
Nibble Stew: Implementing a "mini-LaTeX" in ~2000 lines of code
The input text file for War of the Worlds is about 332 kB in size and the final PDF contains 221 pages. The program generates the output in 7 seconds on a Ryzen 7 3700 using only one core. This problem is fairly easily parallelizable so if one were to use all 16 cores at the same time the whole operation would take less than a second. I did not do exact measurements but the processing speed seems to be within the same order of magnitude as plain LaTeX.
The really surprising thing was that according to Massif the peak memory consumption was 5 MB. I had not tried to save memory when coding and just made copies of strings and other objects without a care in the world and still managed to almost fit the entire workload in the 4 MB L2 cache of the processor. Goes to show that premature optimization really is the root of all evil (or wasted effort at least).
Most CPU cycles are spent inside Pango. This is not due to any perf problems in Pango, but because this algorithm has an atypical work load. It keeps on asking Pango to shape and measure short text segments that are almost but not entirely identical. For each line that does get rendered, Pango had to process ~10 similar blocks of text. The code caches the results so it should only ask for the size of any individual string once, but this is still the bottleneck. On the other hand since you can process a fairly hefty book in 10 seconds or so it is arguable whether further optimizations are even necessary,
-
Python os.system
“Integrating repetitive tasks is a great idea. Shell scripts are frequently used by programmers and software operators to handle some recurring processes. But, shell scripts could get more difficult to manage because these processes get a little more complicated. However, the Python programming language could be utilized for automated processes rather than terminal commands. The same feature as those terminal commands is available in Python through some functions for executing operating system commands.
We can handle computer operations in a systematic and organized manner by acquiring how to execute the command line in Python. The OS package of a python programming language offers tools for cooperating with any operating system of the computer. OS is included in the basic utility packages for Python. This package includes a compact approach of using additional features that rely on the operating system.
The instruction as a string is implemented by the os.system() function in a terminal. The same restrictions apply to this procedure, which would be accomplished by using the system() method of C Programming language. If an instruction produces any outcome, the standard output source of the programmer receives it. When this function is employed, the corresponding operating system terminal is going to open, and the instructions are run there.”
-
Change the View of PyTorch Tensor
“In this PyTorch tutorial, we will see how to change the view of a tensor in PyTorch. PyTorch is an open-source framework available with a Python programming language.
A tensor is a multidimensional array that is used to store the data. So for using a Tensor, we have to import the torch module.
To create a tensor, the method used is tensor()”
-
Compute the Logarithm of Elements of a Tensor in PyTorch
“In this PyTorch tutorial, we will see how to perform logarithmic functions on a given tensor.
PyTorch is an open-source framework available with a Python programming language.
A tensor is a multidimensional array that is used to store the data. So for using a Tensor, we have to import the torch module.
-
How To Exit a Function in Python
As most of us might know, a function in Python is a chunk of code that can be reused when required without having to write it repeatedly. Each program has a particular “flow”. Flow refers to the order in which a program gets executed. In a program, we have lines of code where we initialize variables, take inputs and outputs, and often create and call functions.
We can have one or more functions to perform particular tasks or operations. These functions might or might not return some value or result. However, we need to make a function call for these functions to run and execute. This is necessary.
Once the function has run completely, the next step is to exit the function. For this, we have the “return statement”. The return statement is used (implicitly or explicitly) to exit the function.
-
How to if the Object is a PyTorch Tensor and Return the Metadata of a Tensor in PyTorch?
“In this PyTorch tutorial, we will see how to get the information from the given tensor in PyTorch. PyTorch is an open-source framework available with a Python programming language.
A tensor is a multidimensional array that is used to store the data. So for using a Tensor, we have to import the torch module.
It is possible to check whether the given object is a tensor or not.
torch.is_tensor() is used to check whether the given object is tensor or not.
If the object is a tensor, it will return True otherwise, False.”
-
Logical NOT in PyTorch
“In this PyTorch tutorial, we will see how to perform a logical NOT operation on a tensor using logocal_not(). PyTorch is an open-source framework available with a Python programming language. We can process the data in PyTorch in the form of a Tensor.
A tensor is a multidimensional array that is used to store the data. So for using a Tensor, we have to import the torch module.
To create a tensor, the method used is tensor()”
-
Gawk Scripting Usage Examples
One way of working with files in Linux is using a scripting language to manage the automation of repeated tasks. An example of a good scripting language is awk which makes the extracting of data and working with patterns easy. The GNU implementation of the awk scripting language is gawk. If you are yet to come to terms with its usage, you are in luck. This post presents the different examples of the use of gawk in Linux, and by the end of this guide, you will have a solid understanding of working with it.
-
Create First Spring Boot Application
All these tools are used by the developers to create the spring applications.
Since the Spring Initializer is a mostly used tool, we will start with this first and then we will discuss the other tools in our next articles.
We will use the Eclipse for the development/coding. Eclipse is an IDE that is primarily used to create the java-based applications.
If you are not familiar with Eclipse, don’t worry because it’s a simple code editor. We will help you understand it in this article. To get it, visit the official site https://www.eclipse.org/downloads/ and install it to your local system.