Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Before Posting...
Please check out the Community Guidelines in the Announcements and Administration Category.

generic table usage

Pavel_SPavel_S Member Posts: 74

Hello guys.

Say I have generic table defined by myself (https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/content/ntddk/nf-ntddk-rtlinitializegenerictable) no matter this is AVL nor Splay.

Now, if my "content" of leaves in this tree contains some ULONGs or other simple POD style values I guess this is not a problem, but lets assume I have some strings in it. Is there any option to work on pointers to allocated memory instead of copying data every time I need to get some content?

I assume if I woudl return pointer to originally allocated memory (by allocate function I provided) it will be not thread safe right? Because I will never know if in another thread such content could be deleted... so i would need to have some ref counters to use otriginal memory OR I cna copy data all the time (but doing it under lock looks bit performance invasive). What is good way of handling this issue in general? how you address such issue?

Another question, more to confirm, if AVL tree needs rebalancing I guess under the hood there are no reallocations, but reassinging pointers "beloning" to tree right? I mean that AVL contains some structures and only those are "repinned" and memory allocated for content do not change?

Thank you.

Comments

  • Martin_DrábMartin_Dráb Member - All Emails Posts: 73

    You may work with pointers as elements (so the allocation routine would be called to allocate space for these pointers). Of course, you must ensure the pointers point to valid memory. As far as I read the documentation however, you need to synchronize access to the generic table since it is not thread-safe by its nature (e.g. an exclusive lock should be held when performing an insert operation).

    Another question, more to confirm, if AVL tree needs rebalancing I guess under the hood there are no reallocations, but reassinging pointers "beloning" to tree right? I mean that AVL contains some structures and only those are "repinned" and memory allocated for content do not change?

    I think rebalancing (in both AVL and splay tree cases) should not lead to any memory (de)allocations since tree rotations just work with pointers to left/right child and parent nodes.

    Martin Dráb

  • Pavel_SPavel_S Member Posts: 74
    edited June 24

    Martin thank you for answer.
    I'd say direct usage of pointers depends on case. If however my data is connected to process my guess I cannot use it, because in another thread I may receive termination callback in which I would remove such data and if in another thread Im accessing this data (e.g ecuase I needed to check something there) there is no safe way to do it.

    Actually it doesn't need to be connected to process itself. I think in any scenario when you have multiple readers and multiple writers such scenario may happen.

  • Martin_DrábMartin_Dráb Member - All Emails Posts: 73

    I'd say direct usage of pointers depends on case. If however my data is connected to process my guess I cannot use it, because in another thread I may receive termination callback in which I would remove such data and if in another thread Im accessing this data (e.g ecuase I needed to check something there) there is no safe way to do it.

    I think that reference counting is probably the best option then, provided you can avoid circular references between objects. It is not so hard to implement and solves quite a lot of troubles for you.

    Martin Dráb

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Upcoming OSR Seminars
Writing WDF Drivers 21 Oct 2019 OSR Seminar Space & ONLINE
Internals & Software Drivers 18 Nov 2019 Dulles, VA
Kernel Debugging 30 Mar 2020 OSR Seminar Space
Developing Minifilters 27 Apr 2020 OSR Seminar Space & ONLINE