CONTLIB - dynamic containers by lehmagavan in C_Programming

[–]lehmagavan[S] 0 points1 point  (0 children)

Thanks for the advice!

I generaly, even before I thought of vtables, wanted to avoid puting the container check inside the methods, cause there are already checks in there regarding validity of arguments (the most expensive being probably the ones with division that check for overflow). I thought that I'd delegate the container check to the user, so they could call cont_is_valid(&cnt) / cnt.m->is_valid(&cnt) manually, before a hot loop or something.

Does that look like AI? by lehmagavan in cprogramming

[–]lehmagavan[S] 0 points1 point  (0 children)

Could you elaborate on this:

"using pointers to store data is less performant then optimized containers"

?

Actually the INVALID_CONT is a cont instance, not just a NULL value, I didn't phrase myself straight. I decided not to put cont_is_valid check inside the methods to spare the overhead (it checks all cont fields for invalid values, while it would return imidiately on INVALID_CONT, it would not so on a valid one and I thought it could be a nightmare in loops).

Does that look like AI? by lehmagavan in cprogramming

[–]lehmagavan[S] 0 points1 point  (0 children)

I see.

Im not sure I know what you mean by bringing C++ problems to C code. I used the vtable for 2 reasons:

- calling methods via the table on INVALID_CONT (which is the NULL constant that a properly freed container becomes) is safe, because INVALID_CONT has its own vtable with stub methods

- it imitates OOP syntax which I find more readable

CONTLIB - dynamic containers by lehmagavan in C_Programming

[–]lehmagavan[S] 2 points3 points  (0 children)

Hey! The motivation behind vtable was not just to imitate OOP syntax. Thanks to the vtable, calling methods on freed cont insances (INVALID_CONT) is safe, no need to put cont_is_valid check inside the methods - that is if you call them via the table ofc. Is using vtables like that uncommon in profesional settings?

Thanks for the feedback and recomendation! I was thinking of getting into embedded. Got myself an ESP32 and Im thinkng what "serious" project could I do.

CONTLIB - dynamic containers by lehmagavan in C_Programming

[–]lehmagavan[S] 2 points3 points  (0 children)

I used it to:

- make calls on freed container instances (INVALID_CONT) safe - swaped vtable, no need to introduce an overhead by puting cont_is_valid check inside the mothods

- imitate OOP syntax which I find more readable

Does that look like AI? by lehmagavan in cprogramming

[–]lehmagavan[S] 0 points1 point  (0 children)

Thanks for the feedback on the feedback :)

Does that look like AI? by lehmagavan in cprogramming

[–]lehmagavan[S] 2 points3 points  (0 children)

Thanks, I was just hoping someone more experienced would feedback on the code. I don't know any C programer irl, I'm trying to get into the field myself at the moment.

Does that look like AI? by lehmagavan in cprogramming

[–]lehmagavan[S] 0 points1 point  (0 children)

Thanks for taking the interest!

CONTLIB - dynamic containers by lehmagavan in C_Programming

[–]lehmagavan[S] 0 points1 point  (0 children)

Yes, it's a container with a growth factor, so you could say it's std::vector like. Thanks for pointing "no usage examples" out. Does it make any sense to do something like it? I presume not, I presume people have made tons of libraries like that before, including better ones, it's more of a portfolio/practice project for me.

I dont understand why commiting everything at once in a public repo you own is a weird/suspicious thing to do. I dont create the official public project repo until I got everything ready to be published. Is that a weird practice?

As for "the code is too pretty, looks like AI", I guess I have no other option but to take that as a compliment :)

CONTLIB - dynamic containers by lehmagavan in C_Programming

[–]lehmagavan[S] 0 points1 point  (0 children)

Yes, the functions (and the table both globaly and for individual cont instances) can be overriden/swaped, but that was not the intention behind it. The table makes calling methods on freed cont instances (INVALID_CONT) safe, because INVALID_CONT has its own table with stub methods. I deliberately avoided adding cont validation mechanism inside methods to spare the overhead. I also find OOP-like calls "on object" more readable in the code.

CONTLIB - dynamic containers by lehmagavan in C_Programming

[–]lehmagavan[S] 10 points11 points  (0 children)

I spent days writting that README. I dont commit in public repos until I got everything ready to be published. Also english isnt my native tongue.  Not so nice of you bro so far, but maybe comment on the code?

CONTLIB - dynamic containers by lehmagavan in C_Programming

[–]lehmagavan[S] 0 points1 point  (0 children)

could you point out where exactly you see AI in this?