3 ms·
The trick with doing this in a language without reference counting (like C) is keeping track of who owns the buffer all your slices point to. Windows uses UNIC
by mauvehaus 14y ago
The trick with doing this in a language without reference counting (like C) is keeping track of who owns the buffer all your slices point to. Windows uses UNICODE_STRING[1] internally for a great many things, paths being one of them. There are some functions[2][3] in the FilterManager's API for parsing paths that take advantage of this so as to avoid allocating extra memory for path components that already exist in the original path.
Note also the proscription against modifying the parsed path components[3] because they're shared. Since there's no support for immutable strings, you're counting on everybody to read the documentation and follow it. Admittedly, this specific restriction comes about from getting the file name information from the FilterManager in the first place, which has the explicit purpose of reducing the number of copies of paths floating around in kernel memory, but it still demonstrates the original point of needing to know who owns the memory at the end of the day.
[1]http://msdn.microsoft.com/en-us/library/windows/desktop/aa380518%28v=vs.85%29.aspx http://msdn.microsoft.com/en-us/library/windows/desktop/aa38...
[2]http://msdn.microsoft.com/en-us/library/windows/hardware/ff543413%28v=vs.85%29.aspx http://msdn.microsoft.com/en-us/library/windows/hardware/ff5...
[3]http://msdn.microsoft.com/en-us/library/windows/hardware/ff543417%28v=vs.85%29.aspx http://msdn.microsoft.com/en-us/library/windows/hardware/ff5...