Change memory allocation from heap to stack 95/6895/1
authorwansu.yoo <wansu.yoo@samsung.com>
Wed, 20 Oct 2021 09:57:46 +0000 (18:57 +0900)
committerwansu.yoo <wansu.yoo@samsung.com>
Wed, 20 Oct 2021 09:57:46 +0000 (18:57 +0900)
- Heap allocation takes more time in execution compared to the stack.
- Stack automatically cleans up the object.

Signed-off-by: wansu.yoo <wansu.yoo@samsung.com>
Change-Id: Id268884b886a1ee84f15a522542defcb64c4e721

e2sim/e2sm_examples/kpm_e2sm/src/kpm/encode_kpm.cpp [changed mode: 0644->0755]
e2sim/e2sm_examples/kpm_e2sm/src/kpm/kpm_callbacks.cpp [changed mode: 0644->0755]
e2sim/src/base/e2sim.cpp [changed mode: 0644->0755]
e2sim/src/encoding/encode_e2apv1.cpp [changed mode: 0644->0755]
e2sim/src/messagerouting/e2ap_message_handler.cpp [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index 613e793..b3a0465
@@ -769,7 +769,7 @@ void encode_kpm_report_rancontainer_du_parameterized(E2SM_KPM_IndicationMessage_
 
   indicationmessage->indicationMessage.choice.indicationMessage_Format1 = *format;
 
-  char *error_buf = (char*)calloc(300, sizeof(char));
+  char error_buf[300] = {0, };
   size_t errlen;
 
   asn_check_constraints(&asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage, error_buf, &errlen);
@@ -830,7 +830,7 @@ void encode_kpm_report_rancontainer_cucp_parameterized(E2SM_KPM_IndicationMessag
 
   indicationmessage->indicationMessage.choice.indicationMessage_Format1 = *format;
 
-  char *error_buf = (char*)calloc(300, sizeof(char));
+  char error_buf[300] = {0, };
   size_t errlen;
 
   asn_check_constraints(&asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage, error_buf, &errlen);
@@ -880,7 +880,7 @@ void encode_kpm_report_rancontainer_cucp(E2SM_KPM_IndicationMessage_t* indicatio
 
   indicationmessage->indicationMessage.choice.indicationMessage_Format1 = *format;
 
-  char *error_buf = (char*)calloc(300, sizeof(char));
+  char error_buf[300] = {0, };
   size_t errlen;
 
   asn_check_constraints(&asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage, error_buf, &errlen);
@@ -938,7 +938,7 @@ void encode_kpm_report_rancontainer_cuup_parameterized(E2SM_KPM_IndicationMessag
 
   indicationmessage->indicationMessage.choice.indicationMessage_Format1 = *format;
 
-  char *error_buf = (char*)calloc(300, sizeof(char));
+  char error_buf[300] = {0, };
   size_t errlen;
 
   asn_check_constraints(&asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage, error_buf, &errlen);
@@ -1068,7 +1068,7 @@ void encode_kpm_report_rancontainer_cuup(E2SM_KPM_IndicationMessage_t* indicatio
 
   indicationmessage->indicationMessage.choice.indicationMessage_Format1 = *format;
 
-  char *error_buf = (char*)calloc(300, sizeof(char));
+  char error_buf[300] = {0, };
   size_t errlen;
 
   asn_check_constraints(&asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage, error_buf, &errlen);
@@ -1215,7 +1215,7 @@ void encode_kpm_report_style1_parameterized(E2SM_KPM_IndicationMessage_t* indica
 
   indicationmessage->indicationMessage.choice.indicationMessage_Format1 = *format;
 
-  char *error_buf = (char*)calloc(300, sizeof(char));
+  char error_buf[300] = {0, };
   size_t errlen;
 
   asn_check_constraints(&asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage, error_buf, &errlen);
@@ -1358,7 +1358,7 @@ void encode_kpm_report_style1(E2SM_KPM_IndicationMessage_t* indicationmessage) {
 
   indicationmessage->indicationMessage.choice.indicationMessage_Format1 = *format;
 
-  char *error_buf = (char*)calloc(300, sizeof(char));
+  char error_buf[300] = {0, };
   size_t errlen;
 
   asn_check_constraints(&asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage, error_buf, &errlen);
@@ -1617,7 +1617,7 @@ void encode_kpm_report_style5_parameterized(E2SM_KPM_IndicationMessage_t* indica
 
   indicationmessage->indicationMessage.choice.indicationMessage_Format1 = *format;
 
-  char *error_buf = (char*)calloc(300, sizeof(char));
+  char error_buf[300] = {0, };
   size_t errlen;
 
   asn_check_constraints(&asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage, error_buf, &errlen);
@@ -1787,7 +1787,7 @@ void encode_kpm_report_style5(E2SM_KPM_IndicationMessage_t* indicationmessage) {
 
   indicationmessage->indicationMessage.choice.indicationMessage_Format1 = *format;
 
-  char *error_buf = (char*)calloc(300, sizeof(char));
+  char error_buf[300] = {0, };
   size_t errlen;
 
   asn_check_constraints(&asn_DEF_E2SM_KPM_IndicationMessage, indicationmessage, error_buf, &errlen);
old mode 100644 (file)
new mode 100755 (executable)
index 26958b6..0370984
@@ -245,7 +245,7 @@ void run_report_loop(long requestorId, long instanceId, long ranFunctionId, long
          
          json::json_pointer p5(std::string("/ueMeasReport/ueMeasReportList/") + std::to_string(i) +"/neighbourCellList");
          
-         uint8_t *crnti_buf = (uint8_t*)calloc(1,2);
+         uint8_t crnti_buf[3] = {0, };
 
          if (ueId.find("Pedestrian") != string::npos) {
            std::string ind = ueId.substr(11);
@@ -306,14 +306,14 @@ void run_report_loop(long requestorId, long instanceId, long ranFunctionId, long
            }
 
 
-           uint8_t *neighbor_cellid_buf = (uint8_t*)calloc(1,5);
+           uint8_t neighbor_cellid_buf[6] = {0, };
            neighbor_cellid_buf[0] = 0x22;
            neighbor_cellid_buf[1] = 0x5B;
            neighbor_cellid_buf[2] = 0xD6;
            neighbor_cellid_buf[3] = nextNbCell;
            neighbor_cellid_buf[4] = 0x70;
            
-           char *cid_buf = (char*)calloc(1,24);
+           char cid_buf[25] = {0, };
            get_cell_id(neighbor_cellid_buf,cid_buf);
            
            
@@ -333,22 +333,22 @@ void run_report_loop(long requestorId, long instanceId, long ranFunctionId, long
          const uint8_t *neighbor_buf = reinterpret_cast<const uint8_t*>(neighbor_str.c_str());
 
 
-         uint8_t *nrcellid_buf = (uint8_t*)calloc(1,5);
+         uint8_t nrcellid_buf[6] = {0, };
          nrcellid_buf[0] = 0x22;
          nrcellid_buf[1] = 0x5B;
          nrcellid_buf[2] = 0xD6;
          nrcellid_buf[3] = nextCellId;
          nrcellid_buf[4] = 0x70;
 
-         uint8_t *gnbid_buf = (uint8_t*)calloc(1,3);
+         uint8_t gnbid_buf[4] = {0, };
          gnbid_buf[0] = 0x22;
          gnbid_buf[1] = 0x5B;
          gnbid_buf[2] = 0xD6;
 
-         uint8_t cuupid_buf[1];
+         uint8_t cuupid_buf[2] = {0, };
          cuupid_buf[0] = 20000;
 
-         uint8_t duid_buf[1];
+         uint8_t duid_buf[2] = {0, };
          duid_buf[0] = 20000;
 
          uint8_t *cuupname_buf = (uint8_t*)"GNBCUUP5";   
@@ -557,22 +557,22 @@ void run_report_loop(long requestorId, long instanceId, long ranFunctionId, long
          uint8_t *sd_buf = (uint8_t*)"100";
          uint8_t *plmnid_buf = (uint8_t*)"747";
 
-         uint8_t *nrcellid_buf = (uint8_t*)calloc(1,5);
+         uint8_t nrcellid_buf[6] = {0, };
          nrcellid_buf[0] = 0x22;
          nrcellid_buf[1] = 0x5B;
          nrcellid_buf[2] = 0xD6;
          nrcellid_buf[3] = cellid;
          nrcellid_buf[4] = 0x70;
 
-         uint8_t *gnbid_buf = (uint8_t*)calloc(1,3);
+         uint8_t gnbid_buf[4] = {0, };
          gnbid_buf[0] = 0x22;
          gnbid_buf[1] = 0x5B;
          gnbid_buf[2] = 0xD6;
 
-         uint8_t cuupid_buf[1];
+         uint8_t cuupid_buf[2] = {0, };
          cuupid_buf[0] = 20000;
 
-         uint8_t duid_buf[1];
+         uint8_t duid_buf[2] = {0, };
          duid_buf[0] = 20000;
 
          uint8_t *cuupname_buf = (uint8_t*)"GNBCUUP5";           
old mode 100644 (file)
new mode 100755 (executable)
index 372cc9d..852cbdd
@@ -165,7 +165,7 @@ int E2Sim::run_loop(int argc, char* argv[]){
   
   sctp_buffer_t data;
 
-  char *error_buf = (char*)calloc(300, sizeof(char));
+  char error_buf[300] = {0, };
   size_t errlen;
 
   asn_check_constraints(&asn_DEF_E2AP_PDU, pdu_setup, error_buf, &errlen);
old mode 100644 (file)
new mode 100755 (executable)
index bc8a99f..1416e5e
@@ -409,7 +409,7 @@ void encoding::generate_e2apv1_subscription_request(E2AP_PDU *e2ap_pdu) {
   e2ap_pdu->present = pres5;
   e2ap_pdu->choice.initiatingMessage = initmsg;
 
-  char *error_buf = (char*)calloc(300, sizeof(char));;
+  char error_buf[300] = {0, };
   size_t errlen;
                                                                          
   asn_check_constraints(&asn_DEF_E2AP_PDU, e2ap_pdu, error_buf, &errlen);
@@ -520,7 +520,7 @@ void encoding::generate_e2apv1_subscription_response_success(E2AP_PDU *e2ap_pdu,
   e2ap_pdu->present = pres5;
   e2ap_pdu->choice.successfulOutcome = successoutcome;
 
-  char *error_buf = (char*)calloc(300, sizeof(char));
+  char error_buf[300] = {0, };
   size_t errlen;
 
   asn_check_constraints(&asn_DEF_E2AP_PDU, e2ap_pdu, error_buf, &errlen);
@@ -675,7 +675,7 @@ void encoding::generate_e2apv1_subscription_response(E2AP_PDU *e2ap_pdu, E2AP_PD
   e2ap_pdu->present = pres5;
   e2ap_pdu->choice.successfulOutcome = successoutcome;
 
-  char *error_buf = (char*)calloc(300, sizeof(char));
+  char error_buf[300] = {0, };
   size_t errlen;
 
   asn_check_constraints(&asn_DEF_E2AP_PDU, e2ap_pdu, error_buf, &errlen);
@@ -850,7 +850,7 @@ void encoding::generate_e2apv1_indication_request_parameterized(E2AP_PDU *e2ap_p
   
   e2ap_pdu->present = pres5;
   e2ap_pdu->choice.initiatingMessage = initmsg;
-  char *error_buf = (char*)calloc(300, sizeof(char));
+  char error_buf[300] = {0, };
   size_t errlen;
 
   asn_check_constraints(&asn_DEF_E2AP_PDU, e2ap_pdu, error_buf, &errlen);
old mode 100644 (file)
new mode 100755 (executable)
index 3ecc2f0..81aa780
@@ -246,7 +246,7 @@ void e2ap_handle_E2SeviceRequest(E2AP_PDU_t* pdu, int &socket_fd, E2Sim *e2sim)
 \r
   sctp_buffer_t data;\r
 \r
-  char *error_buf = (char*)calloc(300, sizeof(char));\r
+  char error_buf[300] = {0, };\r
   size_t errlen;\r
 \r
   asn_check_constraints(&asn_DEF_E2AP_PDU, res_pdu, error_buf, &errlen);\r