Menu

Question about byte counters in data reading function

daractive
2019-09-13
2019-09-15
  • daractive

    daractive - 2019-09-13

    Hello,
    During combing throught code of this library I noticed something that puzled me. Data reading function (for example "ReadCharData") use variable "bytesread" to store amount of bytes read from a file, to controll padding and the like, but only sometimes it seems to acount for bytes/element, other times just storing raw "fread" return variable (in this case it seems to see no difference between "bytesread" of the same amount of uint8 an uint16 elements). Is this supposed to be like this?
    Thanks in advence for your time.

     
  • tbeu

    tbeu - 2019-09-13

    This is wrong from the very beginning and bugs me for years. I already introduced variables readresult to improve the situation. One day, l think I will change the Read... and Inflate... functions to change the return value to a simple success/error value since this is the relevant information.

     
  • daractive

    daractive - 2019-09-13

    I considered this variable as mostly "funfact" and maybe some debug help, as it affects basically nothing... Except "Mat_VarRead5" where it's actually used for skipping padding in the file which in turn pushed me to ask this question. But AFAIK simply adding multiplications before "fread"s should be enought to actually tweak this one and get rid of issues with skipping padding. Or atleast that's what I deduced from my, still pretty basic, studies of .mat file documentation.

     
  • tbeu

    tbeu - 2019-09-13

    No, it definitely is not a funfact since it tells you if reading from file was successful. And in case of error you need to react and roll back.

     
  • daractive

    daractive - 2019-09-15

    Yea, I guess you are right. Either way I think that multiplying by size of data element should solve potential problems, since it would correct potential bugs in padding (since it uses "%8" to determine how much padding bytes are needed) while not affecting success checks (as long as they are just checks against "NULL").

     

Log in to post a comment.