xiaoxiang781216 commented on code in PR #7525: URL: https://github.com/apache/nuttx/pull/7525#discussion_r1032804993
########## net/tcp/tcp_conn.c: ########## @@ -586,16 +586,32 @@ FAR struct tcp_conn_s *tcp_alloc_conn(void) void tcp_initialize(void) { -#ifndef CONFIG_NET_ALLOC_CONNS int i; +#ifndef CONFIG_NET_ALLOC_CONNS for (i = 0; i < CONFIG_NET_TCP_CONNS; i++) { /* Mark the connection closed and move it to the free list */ g_tcp_connections[i].tcpstateflags = TCP_CLOSED; dq_addlast(&g_tcp_connections[i].sconn.node, &g_free_tcp_connections); } +#else + FAR struct tcp_conn_s *conn; + + for (i = 0; i < CONFIG_NET_TCP_PREALLOC_CONNS; i++) + { + conn = kmm_zalloc(sizeof(struct tcp_conn_s)); Review Comment: > When using `CONFIG_NET_ALLOC_CONNS` connections are dynamically allocated in the heap. I believe it is much better to have everything in the heap, than scattering things around. kmm_malloc has the 8bytes overhead for each allocation. If you will always allocate something initially, it's better to either define a global array or allocate in a batch. > > It also keeps code simpler I think, But not, now we have two code path to initialize conn. Even worse, we have two option to CONFIG_NET_TCP_PREALLOC_CONNS and NET_TCP_CONNS for the similar config. > and I don't see any drawbacks this way. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org