Click here to Skip to main content
15,910,211 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralProcess command line Pin
confalonieri11-Sep-03 22:54
confalonieri11-Sep-03 22:54 
GeneralRe: Process command line Pin
valikac12-Sep-03 6:09
valikac12-Sep-03 6:09 
GeneralAnother problem with memory Pin
abhi197111-Sep-03 22:44
abhi197111-Sep-03 22:44 
GeneralRe: Another problem with memory Pin
Mike Dimmick12-Sep-03 2:40
Mike Dimmick12-Sep-03 2:40 
GeneralRe: Another problem with memory Pin
David Crow12-Sep-03 2:44
David Crow12-Sep-03 2:44 
GeneralRun a function every 100ms Pin
kurnaziso11-Sep-03 22:41
kurnaziso11-Sep-03 22:41 
GeneralRe: Run a function every 100ms Pin
Dangleberry11-Sep-03 22:58
sussDangleberry11-Sep-03 22:58 
Generalplacement new Pin
Dangleberry11-Sep-03 22:26
sussDangleberry11-Sep-03 22:26 
Hi all, I'm almost there with my array template class, I just have one horrid problem before success Smile | :) . OK, I'm reserving a raw memory chunk using malloc/realloc. If T is an object I am then using the placement new operator (default) to construct the objects inside this reserved block, otherwise I am doing a block initialise on the data. Here's the problem, when I have an array of chars, everything is fine (the placement new path is not necessary), however if I have an array of
<br />
class MyClass<br />
{<br />
public:<br />
  MyClass(void);<br />
  ~MyClass(void);<br />
<br />
  array<char> string1;<br />
  array<char> string2;<br />
};<br />
<br />
//Heart of array template class<br />
HRESULT Allocate(unsigned int alloc)<br />
{<br />
  unsigned int size = sizeof(T);<br />
  if(size > 4)<br />
  {<br />
    //obtain pointer to raw data<br />
    m_pItem = malloc(alloc*size);<br />
<br />
    //Construct the object of type T<br />
    new(m_pItem) T[alloc];<br />
  }else...<br />
}<br />

Malloc reserves enough space for say 10 of these objects and returns a pointer to the data which is stored. The placement new operator then gets passed this pointer, but fatally constructs the object 4 bits on from m_pItem. Its strange because my debug window says new[] returned 0x00322c50 yet if I use T* p = new(m_pItem) T[alloc]; instead, p = 0x00322c54 but the debug window still claims 0x00322c50 was returned??? Also m_pItem shows complete garbage in the debug window (so it ain't there), but looking at the mem address 0x00322c54, I can see the object has been nicely constructed there. What the hell is going on?
GeneralRe: placement new Pin
Dangleberry11-Sep-03 23:55
sussDangleberry11-Sep-03 23:55 
GeneralC++ editor Pin
Jerome Conus11-Sep-03 22:06
Jerome Conus11-Sep-03 22:06 
GeneralRe: C++ editor Pin
berndg12-Sep-03 0:19
berndg12-Sep-03 0:19 
GeneralRe: C++ editor Pin
Neville Franks12-Sep-03 0:26
Neville Franks12-Sep-03 0:26 
GeneralRe: C++ editor Pin
typist12-Sep-03 1:22
typist12-Sep-03 1:22 
GeneralRe: C++ editor Pin
Dangleberry12-Sep-03 1:46
sussDangleberry12-Sep-03 1:46 
GeneralPainting problem in CFormView with overlapping ActiveX Pin
sanskypotov11-Sep-03 21:47
sanskypotov11-Sep-03 21:47 
GeneralRead backwarts from file Pin
Eddie70011-Sep-03 20:29
Eddie70011-Sep-03 20:29 
GeneralRe: Read backwarts from file Pin
Neville Franks12-Sep-03 0:32
Neville Franks12-Sep-03 0:32 
GeneralRe: Read backwarts from file Pin
Dangleberry12-Sep-03 1:49
sussDangleberry12-Sep-03 1:49 
GeneralRe: Read backwarts from file Pin
Mike Dimmick12-Sep-03 2:56
Mike Dimmick12-Sep-03 2:56 
GeneralRe: Read backwarts from file Pin
Eddie70015-Sep-03 1:23
Eddie70015-Sep-03 1:23 
GeneralCListCtrl + InsertColumn Pin
KKR11-Sep-03 19:44
KKR11-Sep-03 19:44 
GeneralRe: CListCtrl + InsertColumn Pin
Jagadeesh VN11-Sep-03 20:21
Jagadeesh VN11-Sep-03 20:21 
GeneralRe: CListCtrl + InsertColumn Pin
KKR11-Sep-03 21:51
KKR11-Sep-03 21:51 
GeneralLayering bitmaps Pin
smjones11-Sep-03 18:38
smjones11-Sep-03 18:38 
GeneralRe: Layering bitmaps Pin
Jagadeesh VN11-Sep-03 20:28
Jagadeesh VN11-Sep-03 20:28 

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.