Closed akalsi87 closed 6 years ago
What is the purpose to not to call one extra malloc()? I mean, anyway you need to call p_socket_new() in order to initialize internal socket state. Thus I don't see any API simplification. Moreover, on Windows WSACreateEvent() is used when creating a socket, and I'm not sure that it doesn't call any memory allocation routines internally. Also changing behaviour of p_socket_new() to not to return an allocated structure will introduce API inconsistency with other parts of the library. So we need a solid reason to change the behaviour of socket creation.
I do understand API compatibility concerns, but the reasoning at my end is more toward considering the cases where connections are short lived and made and destroyed often. By using malloc internally, I'm prevented from even having my own pool.
There should be a p_socket_init(PSocket *)
and then p_socket_new
can call it after the malloc
.
It's unfortunate to take away the options as far as memory management from the client.
Just my 2c.
Yes, I do get your point. But please consider the following:
WSACreateEvent
is called during the socket creation procedure. For sure it allocates system resources which need to be freed with WSACloseEvent
. This already introduces resource allocation (i.e. internal system memory or some data structures). You can't get ride of it.p_mem_set_vtable
function and override all calls to malloc
, free
, etc.malloc
call overweights socket allocation itself in the system.malloc
call during the socket creation is exactly the same one you have described (lot of short-lived connections). On server side usually you create socket and keep it. On client side you can do the same. But if you create and destroy lot of sockets such that a single malloc
becomes a bottleneck of performance, than probably you are doing something wrong. Or you have badly designed interaction between a server and a client. I mean, you should use UDP instead of TCP.I don't see any added value in removing a single malloc
call for the procedure which is not intended to be a performance critical (creating a socket). Of course, it is nice to have a tool which can do everything and everywhere, but this makes this tool overcomplicated to use as well.
Ok. I understand your point of view. Closing.
I was looking through the documentation and found that plibsys sockets use an opaque structure and require a
malloc
call for socket initialization.I was hoping this could be avoided by providing an alternative definition for the socket which uses a fixed size storage for the
fd
(which can be avoid*
on Windows but anint
everywhere else) to avoid the use of the memory allocator.Thoughts?