Skip to content

Commit

Permalink
Added more optimization
Browse files Browse the repository at this point in the history
* Reduced the malloc count to 1 per message.
* Bumped the version numer.
* Regenerate the doc to reflect version number.
  • Loading branch information
kozlovic committed Nov 12, 2015
1 parent a46d0dd commit a17131e
Show file tree
Hide file tree
Showing 33 changed files with 59 additions and 54 deletions.
2 changes: 1 addition & 1 deletion doc/DoxyFile.NATS.Client
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = "NATS C Client"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 1.0.0
PROJECT_NUMBER = 1.0.1

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
2 changes: 1 addition & 1 deletion doc/html/dir_68267d1309a1af8e8297ef4c3efbcdba.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;" >
<div id="projectname">NATS C Client
&#160;<span id="projectnumber">1.0.0</span>
&#160;<span id="projectnumber">1.0.1</span>
</div>
<div id="projectbrief">The nats.io C Client, Supported by Apcera</div>
</td>
Expand Down
2 changes: 1 addition & 1 deletion doc/html/files.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;" >
<div id="projectname">NATS C Client
&#160;<span id="projectnumber">1.0.0</span>
&#160;<span id="projectnumber">1.0.1</span>
</div>
<div id="projectbrief">The nats.io C Client, Supported by Apcera</div>
</td>
Expand Down
2 changes: 1 addition & 1 deletion doc/html/globals.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;" >
<div id="projectname">NATS C Client
&#160;<span id="projectnumber">1.0.0</span>
&#160;<span id="projectnumber">1.0.1</span>
</div>
<div id="projectbrief">The nats.io C Client, Supported by Apcera</div>
</td>
Expand Down
2 changes: 1 addition & 1 deletion doc/html/globals_defs.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;" >
<div id="projectname">NATS C Client
&#160;<span id="projectnumber">1.0.0</span>
&#160;<span id="projectnumber">1.0.1</span>
</div>
<div id="projectbrief">The nats.io C Client, Supported by Apcera</div>
</td>
Expand Down
2 changes: 1 addition & 1 deletion doc/html/globals_enum.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;" >
<div id="projectname">NATS C Client
&#160;<span id="projectnumber">1.0.0</span>
&#160;<span id="projectnumber">1.0.1</span>
</div>
<div id="projectbrief">The nats.io C Client, Supported by Apcera</div>
</td>
Expand Down
2 changes: 1 addition & 1 deletion doc/html/globals_eval.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;" >
<div id="projectname">NATS C Client
&#160;<span id="projectnumber">1.0.0</span>
&#160;<span id="projectnumber">1.0.1</span>
</div>
<div id="projectbrief">The nats.io C Client, Supported by Apcera</div>
</td>
Expand Down
2 changes: 1 addition & 1 deletion doc/html/globals_func.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;" >
<div id="projectname">NATS C Client
&#160;<span id="projectnumber">1.0.0</span>
&#160;<span id="projectnumber">1.0.1</span>
</div>
<div id="projectbrief">The nats.io C Client, Supported by Apcera</div>
</td>
Expand Down
2 changes: 1 addition & 1 deletion doc/html/globals_type.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;" >
<div id="projectname">NATS C Client
&#160;<span id="projectnumber">1.0.0</span>
&#160;<span id="projectnumber">1.0.1</span>
</div>
<div id="projectbrief">The nats.io C Client, Supported by Apcera</div>
</td>
Expand Down
2 changes: 1 addition & 1 deletion doc/html/group__callbacks_group.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;" >
<div id="projectname">NATS C Client
&#160;<span id="projectnumber">1.0.0</span>
&#160;<span id="projectnumber">1.0.1</span>
</div>
<div id="projectbrief">The nats.io C Client, Supported by Apcera</div>
</td>
Expand Down
2 changes: 1 addition & 1 deletion doc/html/group__conn_group.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;" >
<div id="projectname">NATS C Client
&#160;<span id="projectnumber">1.0.0</span>
&#160;<span id="projectnumber">1.0.1</span>
</div>
<div id="projectbrief">The nats.io C Client, Supported by Apcera</div>
</td>
Expand Down
2 changes: 1 addition & 1 deletion doc/html/group__conn_mgt_group.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;" >
<div id="projectname">NATS C Client
&#160;<span id="projectnumber">1.0.0</span>
&#160;<span id="projectnumber">1.0.1</span>
</div>
<div id="projectbrief">The nats.io C Client, Supported by Apcera</div>
</td>
Expand Down
2 changes: 1 addition & 1 deletion doc/html/group__conn_pub_group.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;" >
<div id="projectname">NATS C Client
&#160;<span id="projectnumber">1.0.0</span>
&#160;<span id="projectnumber">1.0.1</span>
</div>
<div id="projectbrief">The nats.io C Client, Supported by Apcera</div>
</td>
Expand Down
2 changes: 1 addition & 1 deletion doc/html/group__conn_sub_group.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;" >
<div id="projectname">NATS C Client
&#160;<span id="projectnumber">1.0.0</span>
&#160;<span id="projectnumber">1.0.1</span>
</div>
<div id="projectbrief">The nats.io C Client, Supported by Apcera</div>
</td>
Expand Down
2 changes: 1 addition & 1 deletion doc/html/group__func_group.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;" >
<div id="projectname">NATS C Client
&#160;<span id="projectnumber">1.0.0</span>
&#160;<span id="projectnumber">1.0.1</span>
</div>
<div id="projectbrief">The nats.io C Client, Supported by Apcera</div>
</td>
Expand Down
2 changes: 1 addition & 1 deletion doc/html/group__inbox_group.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;" >
<div id="projectname">NATS C Client
&#160;<span id="projectnumber">1.0.0</span>
&#160;<span id="projectnumber">1.0.1</span>
</div>
<div id="projectbrief">The nats.io C Client, Supported by Apcera</div>
</td>
Expand Down
2 changes: 1 addition & 1 deletion doc/html/group__library_group.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;" >
<div id="projectname">NATS C Client
&#160;<span id="projectnumber">1.0.0</span>
&#160;<span id="projectnumber">1.0.1</span>
</div>
<div id="projectbrief">The nats.io C Client, Supported by Apcera</div>
</td>
Expand Down
2 changes: 1 addition & 1 deletion doc/html/group__msg_group.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;" >
<div id="projectname">NATS C Client
&#160;<span id="projectnumber">1.0.0</span>
&#160;<span id="projectnumber">1.0.1</span>
</div>
<div id="projectbrief">The nats.io C Client, Supported by Apcera</div>
</td>
Expand Down
2 changes: 1 addition & 1 deletion doc/html/group__opts_group.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;" >
<div id="projectname">NATS C Client
&#160;<span id="projectnumber">1.0.0</span>
&#160;<span id="projectnumber">1.0.1</span>
</div>
<div id="projectbrief">The nats.io C Client, Supported by Apcera</div>
</td>
Expand Down
2 changes: 1 addition & 1 deletion doc/html/group__stats_group.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;" >
<div id="projectname">NATS C Client
&#160;<span id="projectnumber">1.0.0</span>
&#160;<span id="projectnumber">1.0.1</span>
</div>
<div id="projectbrief">The nats.io C Client, Supported by Apcera</div>
</td>
Expand Down
2 changes: 1 addition & 1 deletion doc/html/group__status_group.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;" >
<div id="projectname">NATS C Client
&#160;<span id="projectnumber">1.0.0</span>
&#160;<span id="projectnumber">1.0.1</span>
</div>
<div id="projectbrief">The nats.io C Client, Supported by Apcera</div>
</td>
Expand Down
2 changes: 1 addition & 1 deletion doc/html/group__sub_group.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;" >
<div id="projectname">NATS C Client
&#160;<span id="projectnumber">1.0.0</span>
&#160;<span id="projectnumber">1.0.1</span>
</div>
<div id="projectbrief">The nats.io C Client, Supported by Apcera</div>
</td>
Expand Down
2 changes: 1 addition & 1 deletion doc/html/group__types_group.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;" >
<div id="projectname">NATS C Client
&#160;<span id="projectnumber">1.0.0</span>
&#160;<span id="projectnumber">1.0.1</span>
</div>
<div id="projectbrief">The nats.io C Client, Supported by Apcera</div>
</td>
Expand Down
2 changes: 1 addition & 1 deletion doc/html/group__wildcards_group.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;" >
<div id="projectname">NATS C Client
&#160;<span id="projectnumber">1.0.0</span>
&#160;<span id="projectnumber">1.0.1</span>
</div>
<div id="projectbrief">The nats.io C Client, Supported by Apcera</div>
</td>
Expand Down
2 changes: 1 addition & 1 deletion doc/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;" >
<div id="projectname">NATS C Client
&#160;<span id="projectnumber">1.0.0</span>
&#160;<span id="projectnumber">1.0.1</span>
</div>
<div id="projectbrief">The nats.io C Client, Supported by Apcera</div>
</td>
Expand Down
2 changes: 1 addition & 1 deletion doc/html/modules.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;" >
<div id="projectname">NATS C Client
&#160;<span id="projectnumber">1.0.0</span>
&#160;<span id="projectnumber">1.0.1</span>
</div>
<div id="projectbrief">The nats.io C Client, Supported by Apcera</div>
</td>
Expand Down
2 changes: 1 addition & 1 deletion doc/html/nats_8h.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;" >
<div id="projectname">NATS C Client
&#160;<span id="projectnumber">1.0.0</span>
&#160;<span id="projectnumber">1.0.1</span>
</div>
<div id="projectbrief">The nats.io C Client, Supported by Apcera</div>
</td>
Expand Down
2 changes: 1 addition & 1 deletion doc/html/nats_8h_source.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;" >
<div id="projectname">NATS C Client
&#160;<span id="projectnumber">1.0.0</span>
&#160;<span id="projectnumber">1.0.1</span>
</div>
<div id="projectbrief">The nats.io C Client, Supported by Apcera</div>
</td>
Expand Down
2 changes: 1 addition & 1 deletion doc/html/status_8h.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;" >
<div id="projectname">NATS C Client
&#160;<span id="projectnumber">1.0.0</span>
&#160;<span id="projectnumber">1.0.1</span>
</div>
<div id="projectbrief">The nats.io C Client, Supported by Apcera</div>
</td>
Expand Down
2 changes: 1 addition & 1 deletion doc/html/status_8h_source.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;" >
<div id="projectname">NATS C Client
&#160;<span id="projectnumber">1.0.0</span>
&#160;<span id="projectnumber">1.0.1</span>
</div>
<div id="projectbrief">The nats.io C Client, Supported by Apcera</div>
</td>
Expand Down
39 changes: 22 additions & 17 deletions src/msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ natsMsg_free(void *object)

msg = (natsMsg*) object;

NATS_FREE(msg->buffer);
NATS_FREE(msg);
}

Expand Down Expand Up @@ -78,26 +77,31 @@ natsMsg_create(natsMsg **newMsg,
{
natsMsg *msg = NULL;
char *ptr = NULL;
int totalSize = 0;
int bufSize = 0;

msg = NATS_CALLOC(1, sizeof(natsMsg));
bufSize = subjLen;
bufSize += 1;
bufSize += replyLen;
bufSize += 1;
bufSize += bufLen;
bufSize += 1;

msg = NATS_MALLOC(sizeof(natsMsg) + bufSize);
if (msg == NULL)
return NATS_NO_MEMORY;

totalSize = subjLen;
totalSize += 1;
totalSize += replyLen;
totalSize += 1;
totalSize += bufLen;
totalSize += 1;
// To be safe, we could 'memset' the message up to sizeof(natsMsg),
// but since we are explicitly initializing most of the fields, we save
// on that call, but we need to make sure what we initialize all fields!!!

msg->buffer = NATS_MALLOC(totalSize);
if (msg->buffer == NULL)
{
NATS_FREE(msg);
return NATS_NO_MEMORY;
}
ptr = msg->buffer;
// That being said, we memset the 'gc' structure to protect us in case
// some fields are later added to this 'external' structure and we forget
// about updating this initialization code.
memset(&(msg->gc), 0, sizeof(natsGCItem));

msg->next = NULL;

ptr = (char*) (((char*) &(msg->next)) + sizeof(msg->next));

msg->subject = (const char*) ptr;
memcpy(ptr, subject, subjLen);
Expand All @@ -118,7 +122,8 @@ natsMsg_create(natsMsg **newMsg,
ptr += bufLen;
*(ptr) = '\0';

// Setting the callback will trigger garbage collection
// Setting the callback will trigger garbage collection when
// natsMsg_Destroy() is invoked.
msg->gc.freeCb = natsMsg_free;

*newMsg = msg;
Expand Down
12 changes: 6 additions & 6 deletions src/msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ typedef struct __natsMsg
{
natsGCItem gc;

// This holds subject, reply and payload.
char *buffer;

// These points to specific locations in 'buffer'. They must not be freed.
// (note that we could do without 'subject' since as of now, it is
// equivalent to 'buffer').
// The message is allocated as a single memory block that contains
// this structure and enough space for the payload. The msg payload
// starts after the 'next' pointer.
const char *subject;
const char *reply;
const char *data;
int dataLen;

// Must be last field!
struct __natsMsg *next;

// Nothing after this: the message payload goes there.

} natsMsg;

// PRIVATE
Expand Down
2 changes: 1 addition & 1 deletion src/natsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
//#define DEV_MODE (1)

#define CString "C"
#define Version "1.0.0"
#define Version "1.0.1"

#define NATS_DEFAULT_URL "nats://localhost:4222"

Expand Down

0 comments on commit a17131e

Please sign in to comment.