Click here to Skip to main content
15,898,599 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Winsock question? Pin
Vladimir Georgiev1-Mar-02 6:31
Vladimir Georgiev1-Mar-02 6:31 
GeneralRe: Winsock question? Pin
Vladimir Georgiev1-Mar-02 6:34
Vladimir Georgiev1-Mar-02 6:34 
GeneralRe: Winsock question? Pin
Nish Nishant1-Mar-02 6:43
sitebuilderNish Nishant1-Mar-02 6:43 
GeneralRe: Winsock question? Pin
lucy1-Mar-02 8:08
lucy1-Mar-02 8:08 
Questionhow could i keep the value of a specific pointer? Pin
Gérald Mercet1-Mar-02 3:13
Gérald Mercet1-Mar-02 3:13 
GeneralNet Send Message Pin
1-Mar-02 0:21
suss1-Mar-02 0:21 
GeneralGuarding delete Pin
Joe Moldovan28-Feb-02 23:49
Joe Moldovan28-Feb-02 23:49 
GeneralRe: Guarding delete Pin
Joaquín M López Muñoz1-Mar-02 0:35
Joaquín M López Muñoz1-Mar-02 0:35 
This function determines whether a given pointer belongs in the stack or not:
bool is_stack_memory(void * p)
{
  char check;
  MEMORY_BASIC_INFORMATION m1,m2;
 
  ::ZeroMemory(&m1,sizeof(m1));
  ::ZeroMemory(&m2,sizeof(m2));
  ::VirtualQuery(p,&m1,sizeof(m1));
  ::VirtualQuery(&check,&m2,sizeof(m2));
 
  return m1.BaseAddress==m2.BaseAddress;
}
So you can write code like
if(is_stack_memory(x)){
  printf("x has not been dynamically allocated\n");
  return MDERROR; // or whatever
}
else{
  delete [] x;
}
Anyway, IMHO designing functions around this feature is not a very good idea. I'd restrict the ability to determine whether a pointer is deleteable to doing error checking in debug mode.

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo

PS: There's a limitation in is_stack_memory, namely that it fails to identify pointers on other threads' stacks. This could be worked around, however.
GeneralRe: Guarding delete Pin
Jon Hulatt1-Mar-02 4:12
Jon Hulatt1-Mar-02 4:12 
GeneralRe: Guarding delete Pin
Le centriste1-Mar-02 5:02
Le centriste1-Mar-02 5:02 
GeneralRe: Guarding delete Pin
Joe Moldovan1-Mar-02 11:56
Joe Moldovan1-Mar-02 11:56 
GeneralRe: Guarding delete Pin
Mukkie1-Mar-02 12:06
Mukkie1-Mar-02 12:06 
GeneralTimers are as threads? (newbie) Pin
Joan M28-Feb-02 22:18
professionalJoan M28-Feb-02 22:18 
GeneralRe: Timers are as threads? (newbie) Pin
Joaquín M López Muñoz28-Feb-02 23:41
Joaquín M López Muñoz28-Feb-02 23:41 
GeneralRe: Timers are as threads? (newbie) Pin
Steen Krogsgaard1-Mar-02 3:34
Steen Krogsgaard1-Mar-02 3:34 
GeneralRe: Timers are as threads? (newbie) Pin
Joan M1-Mar-02 4:54
professionalJoan M1-Mar-02 4:54 
GeneralRe: Timers are as threads? (newbie) Pin
Bill Wilson1-Mar-02 6:09
Bill Wilson1-Mar-02 6:09 
GeneralRe: Timers are as threads? (newbie) Pin
Steen Krogsgaard3-Mar-02 21:30
Steen Krogsgaard3-Mar-02 21:30 
QuestionHow to access network shared resource from a service? Pin
28-Feb-02 21:21
suss28-Feb-02 21:21 
AnswerRe: How to access network shared resource from a service? Pin
Bill Wilson1-Mar-02 6:20
Bill Wilson1-Mar-02 6:20 
GeneralStandard Conversions about char Pin
28-Feb-02 19:38
suss28-Feb-02 19:38 
GeneralRe: Standard Conversions about char Pin
Joaquín M López Muñoz28-Feb-02 20:12
Joaquín M López Muñoz28-Feb-02 20:12 
GeneralRe: Standard Conversions about char Pin
Bill Wilson1-Mar-02 8:43
Bill Wilson1-Mar-02 8:43 
GeneralRe: Standard Conversions about char Pin
Tim Smith1-Mar-02 5:27
Tim Smith1-Mar-02 5:27 
GeneralPreventing a Non-resizable form from maximizing when run from a shortcut Pin
outlaw-torn28-Feb-02 19:05
outlaw-torn28-Feb-02 19:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.