{"action":"opened","number":5,"pull_request":{"url":"https://api.github.com/repos/kala13x/slog/pulls/5","id":38915145,"html_url":"https://github.com/kala13x/slog/pull/5","diff_url":"https://github.com/kala13x/slog/pull/5.diff","patch_url":"https://github.com/kala13x/slog/pull/5.patch","issue_url":"https://api.github.com/repos/kala13x/slog/issues/5","number":5,"state":"open","locked":false,"title":"Feature: Dynamically allocate memory","user":{"login":"everte","id":1183038,"avatar_url":"https://avatars.githubusercontent.com/u/1183038?v=3","gravatar_id":"","url":"https://api.github.com/users/everte","html_url":"https://github.com/everte","followers_url":"https://api.github.com/users/everte/followers","following_url":"https://api.github.com/users/everte/following{/other_user}","gists_url":"https://api.github.com/users/everte/gists{/gist_id}","starred_url":"https://api.github.com/users/everte/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/everte/subscriptions","organizations_url":"https://api.github.com/users/everte/orgs","repos_url":"https://api.github.com/users/everte/repos","events_url":"https://api.github.com/users/everte/events{/privacy}","received_events_url":"https://api.github.com/users/everte/received_events","type":"User","site_admin":false},"body":"This pull request changes slog to dynamically allocate enough memory for every log-string we receive. This changes the behaviour from the previous char arrays on the stack, with a maximum defined length, to using functions allocating memory.\r\n\r\nI changed slog this way, because I was running into stack overflow (and resulting segfaults) with the static arrays. To give some context, this happened when logging full JSON responses sending to a client (those can contain for example 15 messages of each 750 characters + html markup). My first naive instinct was to increase the defined MAXMSG constant, but the stack on my operating system seems to be limited to 8196 bytes (by default).\r\n\r\nI've done some testing with valgrind and there should be no memory leaks (at least in the code paths I've been testing).\r\n\r\nOh, since I suspect using an character array on the stack was due to simplicity and performance I did some small scale testing on the performance part. My little test was putting a for loop around the example.c logging code and iterating 1 000 000 times. I did this test on my desktop pc (core i5-4460), with redirecting console output to /dev/null and no logging to file (since I only wanted to measure the memory performance). I did 3 runs for both the original and the modified version and took the average.\r\n\r\n- Current master (with arrays on the stack): ~12.4 seconds\r\n- My pull request (with dynamically allocated arrays): ~14.0 seconds\r\n\r\nThis version is a little bit slower in my little test, but for me it's worth this slowdown because I can throw very long strings at it and it won't complain (crash!). In a real world application, with logging to a file, writing to the file will take so much time that it's even less relevant.\r\n\r\nIt would be great if you would be willing to look at the problem and way I tried to solve it.","created_at":"2015-06-30T19:29:48Z","updated_at":"2015-06-30T19:29:48Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/kala13x/slog/pulls/5/commits","review_comments_url":"https://api.github.com/repos/kala13x/slog/pulls/5/comments","review_comment_url":"https://api.github.com/repos/kala13x/slog/pulls/comments{/number}","comments_url":"https://api.github.com/repos/kala13x/slog/issues/5/comments","statuses_url":"https://api.github.com/repos/kala13x/slog/statuses/43e1ebcfc32eb4ea43cca49f647128be9318c33f","head":{"label":"everte:master","ref":"master","sha":"43e1ebcfc32eb4ea43cca49f647128be9318c33f","user":{"login":"everte","id":1183038,"avatar_url":"https://avatars.githubusercontent.com/u/1183038?v=3","gravatar_id":"","url":"https://api.github.com/users/everte","html_url":"https://github.com/everte","followers_url":"https://api.github.com/users/everte/followers","following_url":"https://api.github.com/users/everte/following{/other_user}","gists_url":"https://api.github.com/users/everte/gists{/gist_id}","starred_url":"https://api.github.com/users/everte/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/everte/subscriptions","organizations_url":"https://api.github.com/users/everte/orgs","repos_url":"https://api.github.com/users/everte/repos","events_url":"https://api.github.com/users/everte/events{/privacy}","received_events_url":"https://api.github.com/users/everte/received_events","type":"User","site_admin":false},"repo":{"id":37927433,"name":"slog","full_name":"everte/slog","owner":{"login":"everte","id":1183038,"avatar_url":"https://avatars.githubusercontent.com/u/1183038?v=3","gravatar_id":"","url":"https://api.github.com/users/everte","html_url":"https://github.com/everte","followers_url":"https://api.github.com/users/everte/followers","following_url":"https://api.github.com/users/everte/following{/other_user}","gists_url":"https://api.github.com/users/everte/gists{/gist_id}","starred_url":"https://api.github.com/users/everte/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/everte/subscriptions","organizations_url":"https://api.github.com/users/everte/orgs","repos_url":"https://api.github.com/users/everte/repos","events_url":"https://api.github.com/users/everte/events{/privacy}","received_events_url":"https://api.github.com/users/everte/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/everte/slog","description":"Advanced logging library for C/C++","fork":true,"url":"https://api.github.com/repos/everte/slog","forks_url":"https://api.github.com/repos/everte/slog/forks","keys_url":"https://api.github.com/repos/everte/slog/keys{/key_id}","collaborators_url":"https://api.github.com/repos/everte/slog/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/everte/slog/teams","hooks_url":"https://api.github.com/repos/everte/slog/hooks","issue_events_url":"https://api.github.com/repos/everte/slog/issues/events{/number}","events_url":"https://api.github.com/repos/everte/slog/events","assignees_url":"https://api.github.com/repos/everte/slog/assignees{/user}","branches_url":"https://api.github.com/repos/everte/slog/branches{/branch}","tags_url":"https://api.github.com/repos/everte/slog/tags","blobs_url":"https://api.github.com/repos/everte/slog/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/everte/slog/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/everte/slog/git/refs{/sha}","trees_url":"https://api.github.com/repos/everte/slog/git/trees{/sha}","statuses_url":"https://api.github.com/repos/everte/slog/statuses/{sha}","languages_url":"https://api.github.com/repos/everte/slog/languages","stargazers_url":"https://api.github.com/repos/everte/slog/stargazers","contributors_url":"https://api.github.com/repos/everte/slog/contributors","subscribers_url":"https://api.github.com/repos/everte/slog/subscribers","subscription_url":"https://api.github.com/repos/everte/slog/subscription","commits_url":"https://api.github.com/repos/everte/slog/commits{/sha}","git_commits_url":"https://api.github.com/repos/everte/slog/git/commits{/sha}","comments_url":"https://api.github.com/repos/everte/slog/comments{/number}","issue_comment_url":"https://api.github.com/repos/everte/slog/issues/comments{/number}","contents_url":"https://api.github.com/repos/everte/slog/contents/{+path}","compare_url":"https://api.github.com/repos/everte/slog/compare/{base}...{head}","merges_url":"https://api.github.com/repos/everte/slog/merges","archive_url":"https://api.github.com/repos/everte/slog/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/everte/slog/downloads","issues_url":"https://api.github.com/repos/everte/slog/issues{/number}","pulls_url":"https://api.github.com/repos/everte/slog/pulls{/number}","milestones_url":"https://api.github.com/repos/everte/slog/milestones{/number}","notifications_url":"https://api.github.com/repos/everte/slog/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/everte/slog/labels{/name}","releases_url":"https://api.github.com/repos/everte/slog/releases{/id}","created_at":"2015-06-23T15:25:30Z","updated_at":"2015-06-23T15:25:30Z","pushed_at":"2015-06-30T19:03:29Z","git_url":"git://github.com/everte/slog.git","ssh_url":"git@github.com:everte/slog.git","clone_url":"https://github.com/everte/slog.git","svn_url":"https://github.com/everte/slog","homepage":null,"size":153,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"kala13x:master","ref":"master","sha":"ac383816f3dd9444889567cdb4a41b3c71970b2d","user":{"login":"kala13x","id":4499431,"avatar_url":"https://avatars.githubusercontent.com/u/4499431?v=3","gravatar_id":"","url":"https://api.github.com/users/kala13x","html_url":"https://github.com/kala13x","followers_url":"https://api.github.com/users/kala13x/followers","following_url":"https://api.github.com/users/kala13x/following{/other_user}","gists_url":"https://api.github.com/users/kala13x/gists{/gist_id}","starred_url":"https://api.github.com/users/kala13x/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kala13x/subscriptions","organizations_url":"https://api.github.com/users/kala13x/orgs","repos_url":"https://api.github.com/users/kala13x/repos","events_url":"https://api.github.com/users/kala13x/events{/privacy}","received_events_url":"https://api.github.com/users/kala13x/received_events","type":"User","site_admin":false},"repo":{"id":33304490,"name":"slog","full_name":"kala13x/slog","owner":{"login":"kala13x","id":4499431,"avatar_url":"https://avatars.githubusercontent.com/u/4499431?v=3","gravatar_id":"","url":"https://api.github.com/users/kala13x","html_url":"https://github.com/kala13x","followers_url":"https://api.github.com/users/kala13x/followers","following_url":"https://api.github.com/users/kala13x/following{/other_user}","gists_url":"https://api.github.com/users/kala13x/gists{/gist_id}","starred_url":"https://api.github.com/users/kala13x/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kala13x/subscriptions","organizations_url":"https://api.github.com/users/kala13x/orgs","repos_url":"https://api.github.com/users/kala13x/repos","events_url":"https://api.github.com/users/kala13x/events{/privacy}","received_events_url":"https://api.github.com/users/kala13x/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/kala13x/slog","description":"Advanced logging library for C/C++","fork":false,"url":"https://api.github.com/repos/kala13x/slog","forks_url":"https://api.github.com/repos/kala13x/slog/forks","keys_url":"https://api.github.com/repos/kala13x/slog/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kala13x/slog/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kala13x/slog/teams","hooks_url":"https://api.github.com/repos/kala13x/slog/hooks","issue_events_url":"https://api.github.com/repos/kala13x/slog/issues/events{/number}","events_url":"https://api.github.com/repos/kala13x/slog/events","assignees_url":"https://api.github.com/repos/kala13x/slog/assignees{/user}","branches_url":"https://api.github.com/repos/kala13x/slog/branches{/branch}","tags_url":"https://api.github.com/repos/kala13x/slog/tags","blobs_url":"https://api.github.com/repos/kala13x/slog/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kala13x/slog/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kala13x/slog/git/refs{/sha}","trees_url":"https://api.github.com/repos/kala13x/slog/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kala13x/slog/statuses/{sha}","languages_url":"https://api.github.com/repos/kala13x/slog/languages","stargazers_url":"https://api.github.com/repos/kala13x/slog/stargazers","contributors_url":"https://api.github.com/repos/kala13x/slog/contributors","subscribers_url":"https://api.github.com/repos/kala13x/slog/subscribers","subscription_url":"https://api.github.com/repos/kala13x/slog/subscription","commits_url":"https://api.github.com/repos/kala13x/slog/commits{/sha}","git_commits_url":"https://api.github.com/repos/kala13x/slog/git/commits{/sha}","comments_url":"https://api.github.com/repos/kala13x/slog/comments{/number}","issue_comment_url":"https://api.github.com/repos/kala13x/slog/issues/comments{/number}","contents_url":"https://api.github.com/repos/kala13x/slog/contents/{+path}","compare_url":"https://api.github.com/repos/kala13x/slog/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kala13x/slog/merges","archive_url":"https://api.github.com/repos/kala13x/slog/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kala13x/slog/downloads","issues_url":"https://api.github.com/repos/kala13x/slog/issues{/number}","pulls_url":"https://api.github.com/repos/kala13x/slog/pulls{/number}","milestones_url":"https://api.github.com/repos/kala13x/slog/milestones{/number}","notifications_url":"https://api.github.com/repos/kala13x/slog/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kala13x/slog/labels{/name}","releases_url":"https://api.github.com/repos/kala13x/slog/releases{/id}","created_at":"2015-04-02T11:05:11Z","updated_at":"2015-06-18T17:57:08Z","pushed_at":"2015-06-24T09:25:49Z","git_url":"git://github.com/kala13x/slog.git","ssh_url":"git@github.com:kala13x/slog.git","clone_url":"https://github.com/kala13x/slog.git","svn_url":"https://github.com/kala13x/slog","homepage":null,"size":380,"stargazers_count":5,"watchers_count":5,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":1,"forks":2,"open_issues":1,"watchers":5,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/kala13x/slog/pulls/5"},"html":{"href":"https://github.com/kala13x/slog/pull/5"},"issue":{"href":"https://api.github.com/repos/kala13x/slog/issues/5"},"comments":{"href":"https://api.github.com/repos/kala13x/slog/issues/5/comments"},"review_comments":{"href":"https://api.github.com/repos/kala13x/slog/pulls/5/comments"},"review_comment":{"href":"https://api.github.com/repos/kala13x/slog/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/kala13x/slog/pulls/5/commits"},"statuses":{"href":"https://api.github.com/repos/kala13x/slog/statuses/43e1ebcfc32eb4ea43cca49f647128be9318c33f"}},"merged":false,"mergeable":null,"mergeable_state":"unknown","merged_by":null,"comments":0,"review_comments":0,"commits":1,"additions":32,"deletions":21,"changed_files":1}}