Difference between revisions of "Prokee Module: mstr"

From prokee
Jump to navigation Jump to search
(Example)
 
Line 2: Line 2:
  
 
== Example ==
 
== Example ==
mstrs<char> *a;
+
<syntaxhighlight lang="C">
mstr::create(&a,10);              // initial memory allocation of 10 Bytes
+
mstrs<char> *a;
mstr::copy_str(a,"Hello World!"); // copying of a string (allocates a larger memory block for 'a')
+
mstr::create(&a,10);              // initial memory allocation of 10 Bytes
printf("%s\n",mstr::c_str(a));
+
mstr::copy_str(a,"Hello World!"); // copying of a string (allocates a larger memory block for 'a')
mstr::destroy(a);                // frees all memory allocated for 'a'
+
printf("%s\n",mstr::c_str(a));
 +
mstr::destroy(a);                // frees all memory allocated for 'a'
 +
</syntaxhighlight>
  
 
== Implementations ==
 
== Implementations ==

Latest revision as of 13:29, 12 June 2019

The module mstr provides basic functionality for strings (like copying, concatenation and comparison) with automated reallocation of larger memory blocks, if required.

Example

mstrs<char> *a;
mstr::create(&a,10);              // initial memory allocation of 10 Bytes
mstr::copy_str(a,"Hello World!"); // copying of a string (allocates a larger memory block for 'a')
printf("%s\n",mstr::c_str(a));
mstr::destroy(a);                 // frees all memory allocated for 'a'

Implementations