| 2857 | } |
| 2858 | |
| 2859 | void *InternalCreateConstBuffer(const void *inData,int inSize,bool inAddStringHash) |
| 2860 | { |
| 2861 | bool addHash = inAddStringHash && inSize>0; |
| 2862 | |
| 2863 | int *result = (int *)HxAlloc(inSize + sizeof(int) + (addHash ? sizeof(int):0) ); |
| 2864 | if (addHash) |
| 2865 | { |
| 2866 | unsigned int hash = 0; |
| 2867 | if (inData) |
| 2868 | for(int i=0;i<inSize-1;i++) |
| 2869 | hash = hash*223 + ((unsigned char *)inData)[i]; |
| 2870 | |
| 2871 | //*((unsigned int *)((char *)result + inSize + sizeof(int))) = hash; |
| 2872 | *result++ = hash; |
| 2873 | *result++ = HX_GC_CONST_ALLOC_BIT | HX_GC_STRING_HASH; |
| 2874 | } |
| 2875 | else |
| 2876 | { |
| 2877 | *result++ = HX_GC_CONST_ALLOC_BIT; |
| 2878 | } |
| 2879 | |
| 2880 | if (inData) |
| 2881 | { |
| 2882 | memcpy(result,inData,inSize); |
| 2883 | } |
| 2884 | else if (inSize) |
| 2885 | { |
| 2886 | ZERO_MEM(result,inSize); |
| 2887 | } |
| 2888 | |
| 2889 | return result; |
| 2890 | } |
| 2891 | |
| 2892 | // Used when the allocation size is zero for a non-null pointer |
| 2893 | void *emptyAlloc = InternalCreateConstBuffer(0,0,false); |