Hi Manu, > In Blackbook5, what does BDictionary.getDataLength return? > .. what should minimumSize include?
First, are you referring to the BFileDir.getDataLength(char *filename) command, being run on a Dictionary file? Dictionary files have special properties to them that allow them to be updated indefinitely. The way it works is when you first open a Dictionary file, you must specify the minimum size. On the flash, Blackbook will reserve *at least* that minimum size to store data - but if you want the background information on that, the actual size on flash will extend to the next page boundary. This can make your actual file size up to 255 bytes larger than you requested. Better a file be made a few bytes too big than too small. After you have opened a Dictionary file for the first time, its footprint on flash will remain constant throughout its lifetime. The dictionary file itself will physically move around to various locations on flash as it fills up and removes invalid keys throughout its lifetime, but the valid (undeletable) footprint on flash will always stay the same. Because flash can't actually "delete" data very easily, is better to leave old data written to flash and just ignore it. That means that as you delete or update existing keys in your Dictionary file, the amount of data in that Dictionary file is growing, not shrinking or changing. There comes a point where the amount of data (invalid + valid data) in the Dictionary file fills up to the size you requested when you first created the file. At that point, the Dictionary file will physically move to another location on flash and copy all the previous valid key-values over, leaving all the old key-value pairs behind (to be deleted by the garbage collector when the time is right). So... if you call getDataLength(..) on your dictionary file, you'll see the size is changing all over the place as you add or update keys - or maybe it changes only after you've closed and opened the file again. However it does it, a better indicator of Dictionary file size is getReservedLength(..), which tells you the dictionary file's footprint on flash. If you were to copy a complete dictionary file from flash to your computer, you'd want to copy its entire footprint, which is getReservedLength(..). The reserved length should remain constant throughout the file's lifetime, as I said. But it could be much bigger than the amount of data actually written to the dictionary file. Also, when you call Bdictionary.open, you get an opened() event with uint32_t totalSize, uint32_t remainingBytes. These two variables give you a snapshot of the state of the Dictionary file, but it's only valid at the time you open the Dictionary file. The amount of actual data in the Dictionary file should be (totalSize - remainingBytes). Back to the minimumSize parameter on open... Because the Dictionary file's footprint remains constant throughout its lifetime, that means that the minimumSize parameter in Bdictionary.open(..) gets completely ignored if it's not the first time you've opened that specific Dictionary file. The minimumSize parameter is only accessed the first time you open a Dictionary file. The larger you make the minimumSize value when you call Bdictionary.open for the first time, then A) you'll be able to store more and larger key-value pairs in your file, and B) it's going to take more time and energy to insert and retrieve key-value pairs as your Dictionary file fills up. And yes, the only real way to count the number of keys is to actually traverse the key list like you mentioned. If Blackbook provided that functionality itself, that's exactly what it would do. And since that's not needed in all applications, it's better to save ROM space for the apps that don't need it and only implement it at a higher level above Blackbook for the apps that do need it. I hope that clears things up and I also hope Blackbook is working out for you. Let me know if you have any more questions -David -----Original Message----- From: Manu Bansal [mailto:[EMAIL PROTECTED] Sent: Monday, September 18, 2006 11:50 AM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: Blackbook5: dataLength, minimumSize for dictionary files Dear Mr. Moss, I am an undergraduate student at Indian Institute of Technology Kanpur (IIT Kanpur), working on a sensor network project and using Blackbook5. There's a question to which I couldn't find an answer in the included pdf or the interface inline comments. I couldn't get any help from the tinyos-help list either, hence a personal mail. In Blackbook5, what does BDictionary.getDataLength return? Is it the length of data inserted as values, or keys and values both, or other? And similarly, what should minimumSize include? For regular files, the semantics is clear, but I'm not sure about dictionary files, and getDataLength doesn't return the expected value. For 5 key-value pairs each having value 12B long, the returned dataLength is 1D/1E/14 on different occasions. Being able to obtain the no. of entries in a dictionary file will also solve my problem. The only way I can think to do this is to traverse the key-link-list. With warm regards and thanks, Manu Bansal. -- Manu Kumar Bansal Fourth Year Undergraduate B.Tech-M.Tech Dual Degree Computer Science and Engineering IIT Kanpur, Kanpur, India - 208016 http://home.iitk.ac.in/~manub _______________________________________________ Tinyos-help mailing list Tinyos-help@Millennium.Berkeley.EDU https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help