Re: Shell Alloc and UNICODE

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



=?Utf-8?B?QWxl?= <Ale@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in news:E1489214-2EF7-
4B4D-89DD-4173779384B8@xxxxxxxxxxxxx:

> While there are memset/wmemset memcpy/wmemcpy, is there a function to
> allocate memory while using UNICODE!?
All memory allocation uses byte counts, by definition.
So there is nothing special about the UNICODE part. If you want to alloc
memory for an array of structs, you multiply the size of the array with
sizeof the struct. Same with Unicode, just multiply with sizeof(WCHAR).

> I've defined this macro:
> #define ShellAlloc(cb) (SHAlloc(cb*sizeof(TCHAR)))
Depends. If the string uses generic data types (TCHAR), then what you did is
ok. SHFileOperation uses generic string types, so probably this is also
what you need.

If the string is always Unicode (i.e. for COM operations), then you
have to use sizeof(WCHAR).

And I would try another name for the macro, something like: SHAllocString,
to make it clear is about strings. You can also do this to have it handy:
#define SHAllocString(cb) (SHAlloc(cb*sizeof(TCHAR)))
#define SHAllocStringW(cb) (SHAlloc(cb*sizeof(WCHAR)))
#define SHAllocStringA(cb) (SHAlloc(cb*sizeof(char)))

You can also alloc 1 more if you want not to take care of the NULL
explicitelly every single time you alloc something.


--
Mihai Nita [Microsoft MVP, Windows - SDK]
------------------------------------------
Replace _year_ with _ to get the real email
.



Relevant Pages

  • Re: Im using about twice as many bytes of memory as the size of the file
    ... StreamReader and then the StreamWriter in case the file has some characters ... you read the whole file into memory before writing the compressed file. ... fact, since the string is stored as Unicode, you are using about twice as ... My question is the text is saying at the end "In fact, since the string is ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Shell Alloc and UNICODE
    ... >> allocate memory while using UNICODE!? ... > All memory allocation uses byte counts, ... > So there is nothing special about the UNICODE part. ... If the string uses generic data types, ...
    (microsoft.public.vc.mfc)
  • Re: Forth utilities?
    ... which I needed: Create a unicode (only for ASCII ... input) string in memory: ... swap drop ... if you need the string as part of an in-memory structure. ...
    (comp.lang.forth)
  • Im using about twice as many bytes of memory as the size of the file
    ... StreamReader and then the StreamWriter in case the file has some characters ... you read the whole file into memory before writing the compressed file. ... fact, since the string is stored as Unicode, you are using about twice as ... My question is the text is saying at the end "In fact, since the string is ...
    (microsoft.public.dotnet.languages.csharp)
  • Forth utilities?
    ... which I needed: Create a unicode (only for ASCII ... input) string in memory: ... swap drop ... if you need the string as part of an in-memory structure. ...
    (comp.lang.forth)