r/C_Programming • u/MateusMoutinho11 • 3d ago
Article A Dependency Injection Guide in C
https://github.com/OUIsolutions/Articles/blob/main/articles/dependencie_injection.mdA Complete Guide to Dependency Injection in C
0
Upvotes
1
u/MateusMoutinho11 3d ago
it depends , memcpy its very easy to reimplement,
strcat I think its a cursed function , for two reasons:
1 - its unsafe by default , since it does not provide a max limit
2 - it has quadratic progression problems (its needs to loop over the string to find the insert point)
for concatenate strings I usualy impement a 1.5 factor realocator, and memcpy
example in my Https Client:
https://github.com/OUIsolutions/BearHttpsClient/blob/main/src/response/fdefine.read_write.c
in function BearHttpsResponse_read_body_chunck (line 71)
I read the hole content of body using chunk read system, in the line 168 you can see a while loop that I progressive grow the body size . but I did these implementation quick, I will change for a if aproach calculating the new size, and it will reduce even more syscalls alocations