User Tools

Site Tools


geda:pcb_data_structures

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

geda:pcb_data_structures [2018/01/27 18:06]
cparker created
geda:pcb_data_structures [2018/09/01 13:01]
cparker
Line 75: Line 75:
 The r-tree data structure hold a copy of the where'​s what data. Meaning that it holds a list of every item on our canvas arranged in successively smaller boxes. The r-tree data structure hold a copy of the where'​s what data. Meaning that it holds a list of every item on our canvas arranged in successively smaller boxes.
 {{:​devel_intro:​rtreepicture.png}} {{:​devel_intro:​rtreepicture.png}}
 +
 +===== object_list =====
 +This is presently available in the home/​cparker/​drc_test branch. Hopefully merged in soon.
 +
 +This is a type for keeping lists of things. It uses void pointers, so, you can keep lists of just about anything you want: pointers, complex data structures, whatever. A list can only hold one type of object. I implemented this, because I found myself implementing similar things over and over again for different types.
 +
 +This explanation needs to be expanded on later, but, briefly, this list just keeps a big block of memory and copies data around inside it. If you hand it a data structure, it makes its own copy of that data structure. A future version might provide an option to take control of an existing structure, but, not right now.
 +
 +Since a list only handles a single type of object, it can calculate where in the block of memory a given index should be. When you ask for an element, it will calculate the location of that element, and give you a pointer to it. Since it knows how many elements are in the list, when you insert at element, it can figure out how much data needs to be moved to make space for the new element.
 +
 +Some objects are more complex than just a block of data. For example, an object might contain a pointer to a string. The object technically owns that string, but if you just make a copy of the object, the pointer will point to the same string. If the original object is deleted, now the list's copy will point to a string that no longer exists. To deal with this, complex objects require the definition of two functions, a clear function and a copy function.
 +
 +The clear function should take care of "​zeroing out" an object. If the object owns other bits of memory, the clear function should free them. It should essentially make the object blank.
 +
 +The copy function should be used to copy an object'​s data, including data that the object owns that is stored elsewhere.
 +
 +I'll eventually put some examples here, but for now, have a look at the unit tests at the end of src/​object_list.c.
geda/pcb_data_structures.txt ยท Last modified: 2018/09/01 13:01 by cparker