[ 
https://issues.apache.org/jira/browse/PROTON-2140?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16979599#comment-16979599
 ] 

ASF GitHub Bot commented on PROTON-2140:
----------------------------------------

astitcher commented on pull request #213: PROTON-2140: Lazy creation of various 
link related objects
URL: https://github.com/apache/qpid-proton/pull/213#discussion_r349285749
 
 

 ##########
 File path: c/src/core/codec.c
 ##########
 @@ -364,37 +364,72 @@ static int pn_data_inspect(void *obj, pn_string_t *dst)
 #define pn_data_hashcode NULL
 #define pn_data_compare NULL
 
-pn_data_t *pn_data(size_t capacity)
+pn_data_t *pni_data(size_t capacity, size_t initial_buffer)
 {
   static const pn_class_t clazz = PN_CLASS(pn_data);
   pn_data_t *data = (pn_data_t *) pn_class_new(&clazz, sizeof(pn_data_t));
   data->capacity = capacity;
   data->size = 0;
   data->nodes = capacity ? (pni_node_t *) malloc(capacity * 
sizeof(pni_node_t)) : NULL;
-  data->buf = pn_buffer(64);
+  data->buf = initial_buffer ? pn_buffer(initial_buffer) : NULL;
   data->parent = 0;
   data->current = 0;
   data->base_parent = 0;
   data->base_current = 0;
-  data->decoder = pn_decoder();
-  data->encoder = pn_encoder();
-  data->error = pn_error();
-  data->str = pn_string(NULL);
+  data->decoder = NULL;
+  data->encoder = NULL;
+  data->error = NULL;
+  data->str = NULL;
   return data;
 }
 
+pn_string_t *pni_data_str(pn_data_t *data)
+{
+  if (data->str == NULL) {
+    data->str = pn_string(NULL);
+  }
+  return data->str;
+}
+
+pn_decoder_t *pni_data_decoder(pn_data_t *data)
+{
+  if (data->decoder == NULL) {
+    data->decoder = pn_decoder();
+  }
+  return data->decoder;
+}
+
+pn_encoder_t *pni_data_encoder(pn_data_t *data)
+{
+  if (data->encoder == NULL) {
+    data->encoder = pn_encoder();
+  }
+  return data->encoder;
+}
+
+pn_data_t *pn_data(size_t capacity)
+{
+  return pni_data(capacity, 64);
+}
+
 void pn_data_free(pn_data_t *data)
 {
   pn_free(data);
 }
 
 int pn_data_errno(pn_data_t *data)
 {
+  if (data->error == NULL) {
 
 Review comment:
   Any reason not to create a `static inline pn_error_t *pni_data_error()` and 
use it here and below? To be consistent with all the other lazy creation 
operations.
   
   I forget whether in C you could just make `pn_data_error()` itself inline 
and then use it here as well.
   
   When using LTO marking inlining is probably less significant as the 
compiler/linker may well spot them anyway, but it does not harm to hint to the 
compiler/linker.
 
----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> proton-c has very high memory footprint for links
> -------------------------------------------------
>
>                 Key: PROTON-2140
>                 URL: https://issues.apache.org/jira/browse/PROTON-2140
>             Project: Qpid Proton
>          Issue Type: Improvement
>            Reporter: Gordon Sim
>            Priority: Major
>




--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@qpid.apache.org
For additional commands, e-mail: dev-h...@qpid.apache.org

Reply via email to