Skip to content

Commit

Permalink
feat: Add option for faster print
Browse files Browse the repository at this point in the history
Can be specified with the long "--highmemuse" option
View randarray.h for the larger blksiz variables
that require the --highmemuse flag
  • Loading branch information
a-random-lemurian committed Dec 31, 2021
1 parent 91104a3 commit 849f139
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 19 deletions.
6 changes: 5 additions & 1 deletion src/randarray.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <stdlib.h>

inline extern void RandomArray_char(int arraySize, int offset, int samplesize,
char chararray[])
char chararray[], int high_mem_use)
{
/* Based on the samplesize, instead define strings of a set size
* based on samplesize. Then flush these strings out of the buffer,
Expand All @@ -42,6 +42,10 @@ inline extern void RandomArray_char(int arraySize, int offset, int samplesize,
blksiz = 10000;
if (samplesize > 10000000)
blksiz = 100000;
if (samplesize > 50000000 && high_mem_use)
blksiz = 200000;
if (samplesize > 100000000 && high_mem_use)
blksiz = 500000;


while (samplesize % blksiz != 0)
Expand Down
13 changes: 9 additions & 4 deletions src/randascii.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
static int help_flag;
static int alphanumeric_flag;
static int ignore_int_limit;
static int high_mem_use;

void PrintHelp(char **argv) {
printf(
Expand All @@ -40,7 +41,10 @@ void PrintHelp(char **argv) {
"-h, --help Print help and exit\n"
"-l, --length Length of ASCII string to print\n"
"--alphanumeric Use alphanumeric characters;\n"
" no punctuation\n",
" no punctuation\n"
"--highmemuse Allocate more memory (~1MB)\n"
" for print buffer (allows for\n"
" faster printing)",
*argv[0]);
}

Expand All @@ -63,7 +67,8 @@ int main(int argc, char **argv)
{"length", required_argument, 0, 'l'},
{"help", no_argument, &help_flag, 1},
{"ignoreintlimit", no_argument, &ignore_int_limit, 1},
{"alphanumeric", no_argument, &alphanumeric_flag, 1}
{"alphanumeric", no_argument, &alphanumeric_flag, 1},
{"highmemuse", no_argument, &high_mem_use, 1},
};

int optindex = 0;
Expand Down Expand Up @@ -97,9 +102,9 @@ int main(int argc, char **argv)
int num_i = CheckOverflow_cchar(ignore_int_limit, samplesize, 10, 1);

if (alphanumeric_flag) {
RandomArray_char(len, offset, num_i, alphanumericAscii);
RandomArray_char(len, offset, num_i, alphanumericAscii, high_mem_use);
return 0;
}

RandomArray_char(len, offset, num_i, printableAscii);
RandomArray_char(len, offset, num_i, printableAscii, high_mem_use);
}
9 changes: 6 additions & 3 deletions src/randfromargs.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "checkoverflow.h"
#include "randarray.h"

static int help_flag, ignore_int_limit;
static int help_flag, ignore_int_limit, high_mem_use;

void PrintHelp(char **argv) {
printf(
Expand All @@ -36,7 +36,9 @@ void PrintHelp(char **argv) {
"options:\n"
"-h, --help Print this message and exit\n"
"-a, --array Array (can be a string, does not support {})\n"
"-l, --length Length of characters to print\n",
"-l, --length Length of characters to print\n"
" --highmemuse Allocate more memory (~1MB) for\n"
" print buffer (allows for faster printing)",
argv[0]);
}

Expand All @@ -56,6 +58,7 @@ int main(int argc, char **argv) {
{"help", no_argument, &help_flag, 1},
{"ignoreintlimit", no_argument, &ignore_int_limit, 1},
{"array", required_argument, NULL, 'a'},
{"highmemuse", no_argument, &high_mem_use, 1}
};

int optindex = 0;
Expand All @@ -79,6 +82,6 @@ int main(int argc, char **argv) {
}

int samplesize_i = CheckOverflow_cchar(ignore_int_limit, samplesize, 10, 1);
RandomArray_char(strlen(array), 0, samplesize_i, array);
RandomArray_char(strlen(array), 0, samplesize_i, array, high_mem_use);

}
19 changes: 12 additions & 7 deletions src/randhex.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,21 @@ static int help_flag;
static int upper_flag;
static int mixed_flag;
static int ignore_int_limit;
static int high_mem_use;

void PrintHelp(char **argv) {
printf(
"Usage: %c [OPTIONS]\n\n"

"options:\n"
"-h, --help Print help and exit\n"
"-l, --length Length of hexadecimal\n"
" numbers to print\n"
" --upper Use uppercase hex letters\n"
" --mixed Use mixedcase hex letters\n",
"-h, --help Print help and exit\n"
"-l, --length Length of hexadecimal\n"
" Use uppercase hex letters\n"
" --mixed Use mixedcase hex letters\n\n"

" --highmemuse Allocate more memory (~1MB)\n"
" for print buffer (allows for\n"
" faster printing)",
*argv[0]);
}

Expand All @@ -60,7 +64,8 @@ int main(int argc, char **argv) {
{"help", no_argument, &help_flag, 1},
{"upper", no_argument, &upper_flag, 1},
{"mixed", no_argument, &mixed_flag, 1},
{"ignoreintlimit", no_argument, &ignore_int_limit, 1}
{"ignoreintlimit", no_argument, &ignore_int_limit, 1},
{"highmemuse", no_argument, &high_mem_use, 1},
};

int optindex = 0;
Expand Down Expand Up @@ -114,5 +119,5 @@ int main(int argc, char **argv) {

int num_i = CheckOverflow_cchar(ignore_int_limit, hexlen, 10, 1);

RandomArray_char(len, offset, num_i, hex);
RandomArray_char(len, offset, num_i, hex, high_mem_use);
}
13 changes: 9 additions & 4 deletions src/randquote.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,20 @@

#include "argcheck.h"

static int help_flag;
static int help_flag, high_mem_use;

void PrintHelp(char** argv)
{
printf(
"Usage: %s [OPTIONS] -f [FILE]\n\n"

"Options:\n"
"-h, --help Print this message and exit\n"
"-f, --file File to select random quote from\n"
"-h, --help Print this message and exit\n"
"-f, --file File to select random quote from\n\n"

" --highmemuse Allocate more memory (~1MB) for\n"
" print buffer (allows for faster\n"
" printing)"
,argv[0]);
}

Expand All @@ -53,7 +57,8 @@ int main (int argc, char** argv)
static struct option longopts[] = {
//{"length", required_argument, 0, 'l'},
{"help", no_argument, &help_flag, 1},
{"file", required_argument, 0, 'f'}
{"highmemuse", no_argument, &high_mem_use, 1},
{"file", required_argument, 0, 'f'},
};

int optindex = 0;
Expand Down

0 comments on commit 849f139

Please sign in to comment.