none
Nested WDFMEMORY objects RRS feed

  • Question

  • Hi,

    I have to store variable-length data in a data structure. The structure is something like

    struct FIXED_DATA{
         WDFMEMORY variableLengthData;     
         size_t length;     
         LONGLONG deviceOffset;
    }

    Since I have to store multiple BLAH objects in my driver, can I do a

    WdfMemoryCreate(WDF_NO_OBJECT_ATTRIBUTES, NonPagedPool, sizeof(FIXED_DATA), &fixed1Memory, NULL);
    WdfCollectionAdd(fixedDataCollection, fixed1Memory);

    Do I have to do anything more than WdfCollectionRemove for every FIXED_DATA memory object? Will the framework clean up the nested WDFMEMORY objects automatically if I specify the same attributes.ParentObject?

    Regards,

    Mridul.



    Tuesday, May 12, 2015 2:40 PM

Answers

  • I would turn your data structure around. FIXED_DATA can be a context on WDFMEMORY (but why do you need the length since the WDFMEMORY can give you the length with an API call?).  Then you just add WDFMEMORYs to the WDFCOLLECTION and when you are done with them, delete them.

    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    • Marked as answer by CraniumRat Tuesday, May 12, 2015 6:59 PM
    Tuesday, May 12, 2015 5:35 PM

All replies

  • Right now you code is making the driver the parent object, so unless you are dereferencing the memory object after you put it in the collection, it will not go away till the driver unloads.

    You say you need multiple objects, what are you going to use these for?  Tell us that and we may be able to give you an approach that works well.


    Don Burn Windows Driver Consulting Website: http://www.windrvr.com

    Tuesday, May 12, 2015 5:21 PM
  • I would turn your data structure around. FIXED_DATA can be a context on WDFMEMORY (but why do you need the length since the WDFMEMORY can give you the length with an API call?).  Then you just add WDFMEMORYs to the WDFCOLLECTION and when you are done with them, delete them.

    d -- This posting is provided "AS IS" with no warranties, and confers no rights.

    • Marked as answer by CraniumRat Tuesday, May 12, 2015 6:59 PM
    Tuesday, May 12, 2015 5:35 PM
  • Thank you, Doron. I did not realize that I could use a context for a WDFMEMORY object.

    Mridul.

    PS: Please start writing your blog again.

    Tuesday, May 12, 2015 7:00 PM