On Linux, look in /proc/getpid()/statm, e.g.
$ cat /proc/$$/statm
4128 728 443 176 0 291 0
you want the sixth number (291 in this case) - that's the size of the data section.
(For avoidance of doubt, within your program you could read that programmatically.)
Update: shell command was to illustrate the contents of the statm file. You wouldn't do that from within your program: just read /proc/self/statm and grab the sixth field: something like (C, rather than C++, but you could use iostream if you so desire, and a bit ugly, but it illustrates the principle):
size_t read_statm (void)
{
unsigned a, b, c, d, e, f;
FILE * const fp = fopen ("/proc/self/statm", "r");
if (NULL == fp)
{
perror ("fopen");
return (size_t)0;
}
if (6 != fscanf (fp, "%u%u%u%u%u%u", &a, &b, &c, &d, &e, &f))
{
perror ("scanf");
(void)fclose (fp);
return (size_t)0;
}
(void)fclose (fp);
return (size_t)f;
}