Preview

Kernel Data Structures

Good Essays
Open Document
Open Document
3107 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Kernel Data Structures
Kernel Data Structures

Umair Hussain Malik p10-6016 p106016@nu.edu.pk

As with any large software project, the Linux kernel provides these generic data structures and primitives to encourage code reuse. Kernel developers should use these data structures whenever possible and not “roll your own” solutions. In the following sections, we cover the most useful of these generic data structures, which are the following: * Linked lists * Queues * Maps * Binary trees

Linked Lists
The linked list is the most common data structure in the Linux kernel which, allows the storage and manipulation of a variable number of elements, called the nodes of the list. The elements in a linked list are dynamically created and inserted into the list. This enables the management of a varying number of elements unknown at compile time and each element in the list contains a pointer to the next element. As elements are added to or removed from the list, the pointer to the next node is simply adjusted.

Singly and Doubly Linked Lists
The simplest data structure representing such a linked list might look similar to the following:
/* an element in a linked list */ struct list_element { void *data; struct list_element *next;
};

In some linked lists, each element also contains a pointer to the previous element. These lists are called doubly linked lists because they are linked both forward and backward. Linked lists that do not have a pointer to the previous element are called singly linked lists.

A data structure representing a doubly linked list would look similar to this:
/* an element in a linked list */ struct list_element { void *data; /* struct list_element *next; struct list_element *prev;
};
Circular Linked Lists
Normally, the last element in a linked list has no next element, it is set to point to a special value, such as NULL, to indicate it is the last element in the list. In some linked lists, the last element does not point to a

You May Also Find These Documents Helpful

  • Satisfactory Essays

    It 218 Week 4 Checkpoint

    • 290 Words
    • 2 Pages

    A pointer can be defined as a memory address. To further explain this definition, we declared a variable of (name). It will look much like this (int name). Every variable will occupy some memory. Now we will declare another variable to under (int name). This variable will be (int name-1), and now this variable is declared as a pointer to (int name).What makes it a pointer is the fact that (name-1) points towards (int name) in a memory storage sense. Basically the pointer to (int name) is the contents of (int name-1). In simple terms, the pointer is not a variable at all. It is the place a specific variable will store and access its information.…

    • 290 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Arrays store items that have the same type of data type like a group of employees’ names and social security numbers for a team of 2000 personal. Pointer is a variable that greatly extends the power and flexibility of a program, each memory location that is used to store data value has an address. The address provides the means for a PC hardware to reference a particular data item.…

    • 485 Words
    • 2 Pages
    Good Essays
  • Good Essays

    Nt1310 Unit 1 Test Paper

    • 381 Words
    • 2 Pages

    1. Create an insert function that will take nodes and add them up in the binary tree.…

    • 381 Words
    • 2 Pages
    Good Essays
  • Good Essays

    7 and Array

    • 500 Words
    • 2 Pages

    7. When a single array element, such as myArray[2], is passed to a method, the method receives _____.…

    • 500 Words
    • 2 Pages
    Good Essays
  • Better Essays

    Structured programming is one of the several different ways in which a programming language can be constructed. "It was originally introduced as a means of getting away from the 'spaghetti' code that was used in the early days and to provide some means by which programmers could more easily follow code written by other programmers." (Hendren, 1998) Structured programming is a procedure-oriented method of designing and coding a program.…

    • 962 Words
    • 4 Pages
    Better Essays
  • Better Essays

    Pointer and Stack

    • 1257 Words
    • 6 Pages

    Here, type is the pointer's base type; it must be a valid C data type and var-name is the name of the pointer variable. The asterisk * you used to declare a pointer is the same asterisk that you use for multiplication. However, in this statement the asterisk is being used to designate a variable as a pointer. Following are the valid pointer declaration:…

    • 1257 Words
    • 6 Pages
    Better Essays
  • Satisfactory Essays

    // FREQUENT SUBTREE MINING ALGORITHM... #include #include #include #include #include #include using namespace std; FILE *fp; int no_of_nodes=0, string_ctr=0, vect_ctr=0, vect_ctr1=0,pos_ctr=0,*pos; struct MyNode { string name; vector children; }*myroot, *myroot1, **tree_pattern, **subtree_pattern; //FUNCTION PROTOTYPES DECLARATION ... static void print_element_names(xmlNode *); static MyNode* preprocess(xmlNode *,MyNode *, int); int printMyNode(MyNode *); void print(MyNode **, int); void print_pos_array(int *,int); int check_child(MyNode *, MyNode *); int main() { xmlDoc *doc = NULL; xmlDoc *doc1 = NULL; xmlNode *root_element = NULL; xmlNode *root_element1 = NULL;…

    • 488 Words
    • 2 Pages
    Satisfactory Essays
  • Better Essays

    Binary Search Tree

    • 1292 Words
    • 6 Pages

    //Program – Binary Search Tree #include<iostream> using namespace std; class node { public: int data; node *left, *right; node() { left=right=NULL; } node(int val) { left=right=NULL; data=val; } }; class bst { private: node *root; void insertNode(node *&rootptr, node *pnew); void deleteNode(node *&root, int delval); int least(node *rootptr); int max(node *rootptr); void pre(node *rootptr); void post(node *rootptr); void in(node *rootptr); int countinternal(node *rootptr, int &count); void printTree(node *p, int level); int search(node *rootptr, int data); public: bst(); void callsearch(int data); void insertBST(int datain); void deleteBST(int data); void displayin(); void displaypost(); void displaypre(); void count(); void print(); void leastele(); void maxele(); }; bst::bst() { root= NULL; } void bst::print() { printTree(root, 0); }; void bst::callsearch(int data) { search(root, data); } int bst::search(node *rootptr, int data) { if(rootptr==NULL) { cout<<"Data not found"; return 0; } else if(rootptr->data==data) cout<<"Element found"<<endl; else if(data<rootptr->data) search(rootptr->left, data); else search(rootptr->right, data); } void bst::count() { int c=0; cout<<"The number of internal nodes is: "<<countinternal(root, c)<<endl; } int bst::countinternal(node *rootptr,int &count) { if(rootptr!=NULL) { countinternal(rootptr->left, count); if(rootptr->right!=NULL || rootptr->left!=NULL)…

    • 1292 Words
    • 6 Pages
    Better Essays
  • Powerful Essays

    1.1 INTRODUCTION Data structure is the branch of computer science that unleashes the knowledge of how the data should be organized, how the flow of data should be controlled and how a data structure should be designed and implemented to reduce the complexity and increase the efficiency of the algorithm. The theory of structures not only introduces the data structures, but also helps to understand and use the concept of abstraction, analyze problems step by step and develop algorithms to solve real world problems. Thus it enables various data structures like stacks, queue, linked list, trees and graphs. Effective use of principles of data structures increases efficiency of algorithms to solve problems like searching, sorting, populating and handling voluminous data. 1.2 Basic Terminology of Data Organization Data: The term data means a value or set of values. For example, marks of students, figures obtained during exit polls etc. The data is stored in the memory of computer. Different models are used to organize data in the memory. For example, the model used to organize the data in main memory are collectively referred to as data structures, whereas the different models used to organize data in the secondary memory are collectively referred to as file structures. Data item:- A data item means a single unit of values. For example, roll number, name, address etc. Entity: Entity is something that has certain qualities, characteristics, properties or attributes that may contain some values. For example, Student is an entity. The attributes of student may be roll number, name, address, etc, The values of these attributes may be 100, Ram, House No. 133-A, Pragati Vihar, Delhi. Entity Set: An entity set is a group of or set of similar entities. For example, employees of an organization, students of a class etc. Information: When the data is processed by applying certain rules, new processed data is called information. The data are not useful for decision…

    • 2894 Words
    • 12 Pages
    Powerful Essays
  • Good Essays

    Array Representation

    • 338 Words
    • 2 Pages

    A complete binary tree has a simple array representation. Suppose we number the nodes from left to right, beginning at the top and ending at the bottom. Then we can store the various data items in the corresponding elements of an array. For example…

    • 338 Words
    • 2 Pages
    Good Essays
  • Powerful Essays

    Preface Introduction Chapter 1: What is a Pointer? Chapter 2: Pointer Types and Arrays. Chapter 3: Pointers and Strings Chapter 4: More on Strings Chapter 5: Pointers and Structures Chapter 6: More on Strings and Arrays of Strings Chapter 7: More on Multi-Dimensional Arrays Chapter 8: Pointers to Arrays Chapter 9: Pointers and Dynamic Allocation of Memory Chapter 10: Pointers to Functions…

    • 9878 Words
    • 40 Pages
    Powerful Essays
  • Powerful Essays

    This assignment has three purposes. The first is to give you experience with representations based on list structures and with methods for list processing that manipulate them. To complete the exercise, you must implement a system that stores information using embedded lists and that alters these structures through a series of operations.…

    • 1466 Words
    • 6 Pages
    Powerful Essays
  • Good Essays

    Linked list

    • 1308 Words
    • 6 Pages

    • Unary operator sizeof is used to determine the size in bytes of any data…

    • 1308 Words
    • 6 Pages
    Good Essays
  • Powerful Essays

    memory layout

    • 3957 Words
    • 16 Pages

    A text segment , also known as a code segment or simply as text, is one of the sections of a program in an object file or in memory, which contains executable instructions.…

    • 3957 Words
    • 16 Pages
    Powerful Essays
  • Powerful Essays

    Input and Output Devices

    • 2370 Words
    • 10 Pages

    In computer architecture, the combination of the CPU and main memory (i.e. memory that the CPU can read and write to directly, with individual instructions) is considered the brain of a computer, and from that point of view any transfer of information from or to that combination, for example to or from a disk drive, is considered I/O. The CPU and its supporting circuitry provide memory-mapped I/O that is used in low-level computer programming in the implementation of device drivers. An I/O algorithm is one designed to exploit locality and…

    • 2370 Words
    • 10 Pages
    Powerful Essays