Armenian Knowledge Base  

Go Back   Armenian Knowledge Base > Technical sections > Languages, Compilers, Interpreters
Register

Reply
 
LinkBack Thread Tools
Old 02.03.2002, 12:33   #1
the mochinger
 
Hans Andersen's Avatar
 
Join Date: 02 2002
Location: Paranoid Android, @10:50
Age: 38
Posts: 1,894
Downloads: 2
Uploads: 0
Reputation: 204 | 4
Exclamation heap-py object? :)

define a class in C++, with a method
bool onHeap() const;
which returns true iff the object was created on heap.

ladies and gentlemen, your elegant classes are welcome <img src="smooch-1.gif" border="0">
Reply With Quote
Old 03.03.2002, 19:04   #2
The Reloaded
 
Aram Hambardzumyan's Avatar
 
Join Date: 01 2002
Location: behind the flesh and gelatinе of soft dull eyes
Posts: 3,387
Downloads: 4
Uploads: 0
Reputation: 146 | 4
Post

<blockquote><font size="1" face="MS Sans Serif, Verdana, Helvetica, sans-serif">quote:</font><hr>Originally posted by Hans Andersen:
define a class in C++, with a method
bool onHeap() const;
which returns true iff the object was created on heap.

ladies and gentlemen, your elegant classes are welcome <img src="smooch-1.gif" border="0">
<hr></blockquote>

но зачем?!?
Reply With Quote
Old 04.03.2002, 09:58   #3
the mochinger
 
Hans Andersen's Avatar
 
Join Date: 02 2002
Location: Paranoid Android, @10:50
Age: 38
Posts: 1,894
Downloads: 2
Uploads: 0
Reputation: 204 | 4
Post

amen inch chi vor 'zachemov' a <img src="smooch-1.gif" border="0">
Reply With Quote
Old 04.03.2002, 17:30   #4
Академик
 
greka's Avatar
 
Join Date: 09 2001
Location: inside myself
Posts: 5,369
Downloads: 0
Uploads: 0
Reputation: 18 | 5
Post

of course you have to call API
function "bool IsDataOnHeap(const void*)"
<img src="wink-5.gif" border="0">

I think that we have to find out the address of process's heap(-s) and walk by them, comparing address of the object with the range of that heap spaces.

h-m... <img src="smooch-1.gif" border="0"> ?
__________________
И повешенные могут качаться в неположенную сторону. /С.Е.Лец/
Reply With Quote
Old 04.03.2002, 20:04   #5
The Reloaded
 
Aram Hambardzumyan's Avatar
 
Join Date: 01 2002
Location: behind the flesh and gelatinе of soft dull eyes
Posts: 3,387
Downloads: 4
Uploads: 0
Reputation: 146 | 4
Post

<blockquote><font size="1" face="MS Sans Serif, Verdana, Helvetica, sans-serif">quote:</font><hr>Originally posted by Greco El:
of course you have to call API
function "bool IsDataOnHeap(const void*)"
<hr></blockquote>

no, it seems that standard language features are to be used only <img src="smooch-1.gif" border="0"> this has been discussed by mayers
Reply With Quote
Old 04.03.2002, 23:17   #6
Младенец
 
Join Date: 11 2001
Location: Armenia
Posts: 11
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Talking

class A{
bool IsInHeap;
public:
A():IsInHeap(false){}
bool OnHeap(){return IsInHeap;}
void* operator new(size_t size)
{
IsInHeap=true;
...
}
};
Reply With Quote
Old 04.03.2002, 23:23   #7
Младенец
 
Join Date: 11 2001
Location: Armenia
Posts: 11
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Talking

class A{
public:
bool OnHeap(){return true;}
private:
~A(){}
};
<img src="smooch-1.gif" border="0"> <img src="smooch-1.gif" border="0"> <img src="smooch-1.gif" border="0"> <img src="smooch-1.gif" border="0"> <img src="biggrin2.gif" border="0">
Reply With Quote
Old 05.03.2002, 00:28   #8
The Reloaded
 
Aram Hambardzumyan's Avatar
 
Join Date: 01 2002
Location: behind the flesh and gelatinе of soft dull eyes
Posts: 3,387
Downloads: 4
Uploads: 0
Reputation: 146 | 4
Post

<blockquote><font size="1" face="MS Sans Serif, Verdana, Helvetica, sans-serif">quote:</font><hr>Originally posted by Taurus:
class A{
bool IsInHeap;
public:
A():IsInHeap(false){}
bool OnHeap(){return IsInHeap;}
void* operator new(size_t size)
{
IsInHeap=true;
<hr></blockquote>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
unknown identifier!!!
Reply With Quote
Old 05.03.2002, 02:22   #9
the mochinger
 
Hans Andersen's Avatar
 
Join Date: 02 2002
Location: Paranoid Android, @10:50
Age: 38
Posts: 1,894
Downloads: 2
Uploads: 0
Reputation: 204 | 4
Arrow

to El:
As Aram said, u must use only C++ <img src="smooch-1.gif" border="0"> )
to Taurus:
Sur, Aramy (inchpes misht <img src="smooch-1.gif" border="0"> ) chisht a asum, qo operator new()-n static a <img src="smooch-1.gif" border="0">
urish ban gti <img src="smooch-1.gif" border="0">

to All:
come onnn, ppl, luzeq tenanq <img src="smooch-1.gif" border="0">
__________________
The flower that blooms in adversity is the most rare and beautiful of all.
Reply With Quote
Old 05.03.2002, 02:29   #10
the mochinger
 
Hans Andersen's Avatar
 
Join Date: 02 2002
Location: Paranoid Android, @10:50
Age: 38
Posts: 1,894
Downloads: 2
Uploads: 0
Reputation: 204 | 4
Post

<blockquote><font size="1" face="MS Sans Serif, Verdana, Helvetica, sans-serif">quote:</font><hr>Originally posted by Taurus:
class A{
public:
bool OnHeap(){return true;}
private:
~A(){}
};
<img src="smooch-1.gif" border="0"> <img src="smooch-1.gif" border="0"> <img src="smooch-1.gif" border="0"> <img src="smooch-1.gif" border="0"> <img src="biggrin2.gif" border="0">
<hr></blockquote>

<img src="biggrin2.gif" border="0"> <img src="biggrin2.gif" border="0"> <img src="biggrin2.gif" border="0">
Reply With Quote
Old 05.03.2002, 15:50   #11
Академик
 
greka's Avatar
 
Join Date: 09 2001
Location: inside myself
Posts: 5,369
Downloads: 0
Uploads: 0
Reputation: 18 | 5
Talking

nu, narod, postol'ku poskol'ku debaty razvivajutsa, porobuem vnesti svoju leptu <img src="wink-5.gif" border="0">

Ne xotite sistemnyx spiskov HEAP-nutoj pamjati, budem ispol'zovat' sobstvennuju:


class famous_A
{
private:
static list<VOID_PTR> lst;

public:
bool IsDataOnHeap()
{ const void *ptr = (void*)this;
list<VOID_PTR>::iterator it = find( lst.begin(), lst.end(), ptr );

return ( it != lst.end() );
}

void * operator new(size_t size)
{ void *ptr = : <img src="embarrassed.gif" border="0"> perator new( size );
lst.push_front( ptr );
return ptr;
}

void operator delete(void *ptr)
{ list<VOID_PTR>::iterator it = find( lst.begin(), lst.end(), ptr );

if ( it != lst.end() )
{
: <img src="embarrassed.gif" border="0"> perator delete(ptr);
lst.erase(it);
}
}
};


list<VOID_PTR> famous_A::lst;

<img src="tounge.gif" border="0">
Reply With Quote
Old 05.03.2002, 15:54   #12
Академик
 
greka's Avatar
 
Join Date: 09 2001
Location: inside myself
Posts: 5,369
Downloads: 0
Uploads: 0
Reputation: 18 | 5
Wink

rojicy v topike smotrjatsa koloritno, ne tak li...?
<img src="smooch-1.gif" border="0">
Reply With Quote
Old 05.03.2002, 17:11   #13
The Reloaded
 
Aram Hambardzumyan's Avatar
 
Join Date: 01 2002
Location: behind the flesh and gelatinе of soft dull eyes
Posts: 3,387
Downloads: 4
Uploads: 0
Reputation: 146 | 4
Post

<blockquote><font size="1" face="MS Sans Serif, Verdana, Helvetica, sans-serif">quote:</font><hr>Originally posted by Greco El:
nu, narod, postol'ku poskol'ku debaty razvivajutsa, porobuem vnesti svoju leptu <img src="wink-5.gif" border="0">

Ne xotite sistemnyx spiskov HEAP-nutoj pamjati, budem ispol'zovat' sobstvennuju:

[...skiped...]

<hr></blockquote>

а будет ли это работать, если я унаследуюсь каким-нибудь виртуально-множественным образом от этого класса, создам объект наследника, и от него запрошу IsDataOnHeap()? <img src="smooch-1.gif" border="0"> ведь this уже будет не непосредственно тот, что у нас в списке <img src="wink-5.gif" border="0">
Reply With Quote
Old 05.03.2002, 21:59   #14
Академик
 
greka's Avatar
 
Join Date: 09 2001
Location: inside myself
Posts: 5,369
Downloads: 0
Uploads: 0
Reputation: 18 | 5
Wink

Gol' na vydumki xitra <img src="wink-5.gif" border="0">

na etot sluchaj mojno ispol'zovat' konechno je metod "IsDataOnHeap()", toka ego nado budet podredaktirovat' tak:

bool IsDataOnHeap(const void *ptr)
{
list<VOID_PTR>::iterator it = find( lst.begin(), lst.end(), ptr );

return ( it != lst.end() );
}

Vse-taki peredavat' nado budet.
Esli ne nravitsa nalichie dvux odinakovyx funkcij, to ostavljaem odnu:
bool IsDataOnHeap(const void *ptr=NULL)
libo
bool IsDataOnHeap(const void *ptr)
{
void *ppp;
ppp = (ptr) ? prt : this;
// then use "ppp"...
}

<img src="smooch-1.gif" border="0">

Eshe zamechanija ..? <img src="graemlins/nod.gif" border="0" alt="[Agree]" />
Reply With Quote
Old 06.03.2002, 11:32   #15
the mochinger
 
Hans Andersen's Avatar
 
Join Date: 02 2002
Location: Paranoid Android, @10:50
Age: 38
Posts: 1,894
Downloads: 2
Uploads: 0
Reputation: 204 | 4
Post

Congratulations El,
a good approach <img src="smooch-1.gif" border="0"> osobenno klevo vygledit golobal operator new <img src="smooch-1.gif" border="0"> ))

No tut small-ik 'no' est':
-----
[QUOTE]Originally posted by Greco El:
[QB]Gol' na vydumki xitra <img src="wink-5.gif" border="0">

na etot sluchaj mojno ispol'zovat' konechno je metod "IsDataOnHeap()", toka ego nado budet podredaktirovat' tak:
-----
kto budet insert-nut' derived ukazatel v tvoj spisok? <img src="smooch-1.gif" border="0"> a little improvement is needed.


kto nibud' method pokoroche i poshustree? <img src="smooch-1.gif" border="0">
Reply With Quote
Sponsored Links
Reply

Thread Tools


На правах рекламы:
реклама

All times are GMT. The time now is 07:04.


Powered by vBulletin® Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.