Checking Dynamic Memory Cross-platform

Suppose:
1
2
cin >> number;
pointer = new type[number + (rand()%number);

So, I wont know the memory allocated for pointer. How can I check it in all OS?
1
2
3
4
5
cin >> number;
int allocAmount = number + (rand() % number);
pointer = new type[allocAmount];
// Amount of memory allocated == allocAmount
// (unless line 3 throws an exception, of course) 
Yep. I need to check it without this trick :| .
I'm pretty sure that the size information for new[]/delete[] is stored in some compiler-specific way (in other words, it could be different depending on the compiler).

So either use a variable like I showed above, or consider using std::vector instead:
1
2
3
cin >> number;
vector<type> vec(number + (rand() % number));
// Size == vec.size() 
@long double main I need to track it. I'm preety sure that is OS dependent.
Topic archived. No new replies allowed.