Hi Pete,

Typically, a 'read/write to memory manager data structures' error, implies
either a lost pointer, or a memory allocation error.

In this case, you have a memory allocation error. In your source code, you
are allocating the string space as:
    ...
    strP = MemPtrNew(sizeof(CharPtr));
    ...
thus allocating 4 bytes for your string. The reason the error is infrequent
is the fact that you don't convert many integers over 3 digits (3 chars,
plus the terminating null). When you convert integers greater than 999,
StrIToA starts writing after the allocated space, over the memory manager's
structs.

Unsigned ints are 32 bits long, so range from 0 to 4294967296. Allocate a
string for 10 chars:
    ...
    strP = MemPtrNew(11 * sizeof(char));
    ...

Either that or, if you are over-zealous about your memory space, find the
base 10 logarithm of the int to be converted.

pete moss wrote:

> i get an error in pose that says i am reading from or writing to memory
> manager data structures.  it happens when i use the following function:
>
> static void SetFieldInt(Int fieldID, UInt value)
> {
>         FieldPtr fld;
>         CharPtr strP;
>         FormPtr frm = FrmGetActiveForm();
>
>         strP=MemPtrNew(sizeof(CharPtr));
>         StrIToA(strP, value);
>         fld = FrmGetObjectPtr(frm, FrmGetObjectIndex(frm, fieldID));
>         FldDelete(fld, 0, FldGetTextLength(fld));
>         FldInsert(fld, strP, StrLen(strP));
>         MemPtrFree(strP);
> }
>
> i use this same function on another form in my app, but i never get this
> error.  i have looked and looked, but i cannot figure this out.
>
> three questions:
> 1.  anyone know what this memory manager data structures bit is about?
> 2.  can this function be causing this?
> 3.  why does it never happen in the other form?
>
> this error only happens infrequently, and doesnt cause any damage if i
> select to continue through it.  strange.
>
> :P

--
Sergio Carvalho
---------------
[EMAIL PROTECTED]

If at first you don't succeed, skydiving is not for you


Reply via email to