My contribution to the Arduino community


i have used number of other people's libraries here contribution wants try them.

a mfc cstring class has minimal temporary use of dynamic memory few copying etc functions, dynamic memory deleted before function exits. other these actual strings stored in global or stack memory.

for convenience have number of cbuff... classes save bit of typing. instead of doing
code: [select]

char strbuff[25];
memset(strbuff, 0, 25);
cstring str(strbuff, 25);

you can this
code: [select]
cbuff24 buff;
cstring str(strbuff);

it necessary declare cbuff...classes explicitly following, requires specific cstring constructors.

if there c++ tricks don't know of allow specify buffer size in single class cbuff constructor, not necessitate use of dynamic memory, ears.
code: [select]


class cbuff512
{
public:
cbuff512()
{
  memset(m_strbuff, 0, m_nbuffsize);
}
void erase()
{
  memset(m_strbuff, 0, m_nbuffsize);
}
static const uint16_t m_nbuffsize = 513;
char m_strbuff[m_nbuffsize];
};

class cbuff256
{
public:
cbuff256()
{
  memset(m_strbuff, 0, m_nbuffsize);
}
void erase()
{
  memset(m_strbuff, 0, m_nbuffsize);
}
static const uint16_t m_nbuffsize = 257;
char m_strbuff[m_nbuffsize];
};

class cbuff128
{
public:
cbuff128()
{
memset(m_strbuff, 0, m_nbuffsize);
}
void erase()
{
memset(m_strbuff, 0, m_nbuffsize);
}
static const uint8_t m_nbuffsize = 129;
char m_strbuff[m_nbuffsize];
};

you seem think there important difference between using stack, , using "dynamic memory" (a silly term means using heap memory)?  come out of opposite ends of same memory pool, , if you're deleting memory before function exits, there no significant functional difference between two.  using of either crash system same.

regards,
ray l.


Arduino Forum > Community > Exhibition / Gallery > My contribution to the Arduino community


arduino

Comments

Popular posts from this blog

DHT11 Time out error using v0.4.1library

Sketch upload fails with Java error (___REMOVE___/bin/avrdude)!

Arduino Uno + KTY81/210 temperature sensor