hello everyone! what I want to ask is just like tittle said:

why do not use sdshdr5 for key storage, I think keys no need to be changed?

` source code in sds.h: sds sdsnewlen(const void *init, size_t initlen) { ......

if (type == SDS_TYPE_5 && initlen == 0) type = SDS_TYPE_8;

...... `

as the code above said: sdshdr5 is never used?

Comment From: oranagra

@01-dotcom why do you say that they're not?

rdb.c allocates keys with this code:

if ((key = rdbGenericLoadStringObject(rdb,RDB_LOAD_SDS,NULL)) == NULL)

ultimately that goes to

sdsnewlen(SDS_NOINIT,len)

so initlen is not 0, snd SDS_TYPE_5 can be used.

similarly, when a new key is added via a command, dbAdd does:

sds copy = sdsdup(key->ptr);

so in this case initlen is also not 0.

Comment From: 01-dotcom

Thank you very much!

The sds.h file saied

`

/ Note: sdshdr5 is never used, we just access the flags byte directly. * However is here to document the layout of type 5 SDS strings. / struct attribute ((packed)) sdshdr5 { unsigned char flags; / 3 lsb of type, and 5 msb of string length / char buf[]; };

`

Comment From: oranagra

the comment means that the struct isn't being used (no one casts pointers to that type or writes to its members).

Comment From: 01-dotcom

OK, means that the sdshdr5 string no need to be changed? so len and alloc field is Redundant? [Note: sdshdr5 is never used, we just access the flags byte directly. ] is mean that , sdshdr5 just has buf and flags fileld

Comment From: oranagra

the struct and fields are there just to make a statement. i.e. a kind of documentation that explains the memory layout.

Comment From: 01-dotcom

ok, thank you.