• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ NS_Alloc函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中NS_Alloc函数的典型用法代码示例。如果您正苦于以下问题:C++ NS_Alloc函数的具体用法?C++ NS_Alloc怎么用?C++ NS_Alloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NS_Alloc函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: NS_ERROR

PRBool
nsTArray_base::EnsureCapacity(size_type capacity, size_type elemSize) {
  // This should be the most common case so test this first
  if (capacity <= mHdr->mCapacity)
    return PR_TRUE;

  // If the requested memory allocation exceeds size_type(-1)/2, then our
  // doubling algorithm may not be able to allocate it.  Additionally we
  // couldn't fit in the Header::mCapacity member. Just bail out in cases
  // like that.  We don't want to be allocating 2 GB+ arrays anyway.
  if (capacity * elemSize > size_type(-1)/2) {
    NS_ERROR("Attempting to allocate excessively large array");
    return PR_FALSE;
  }

  if (mHdr == &sEmptyHdr) {
    // NS_Alloc new data
    Header *header = static_cast<Header*>
                                (NS_Alloc(sizeof(Header) + capacity * elemSize));
    if (!header)
      return PR_FALSE;
    header->mLength = 0;
    header->mCapacity = capacity;
    header->mIsAutoArray = 0;
    mHdr = header;
    
    return PR_TRUE;
  }

  // Use doubling algorithm when forced to increase available capacity.
  capacity = PR_MAX(capacity, mHdr->mCapacity << 1);

  Header *header;
  if (UsesAutoArrayBuffer()) {
    // NS_Alloc and copy
    header = static_cast<Header*>
                        (NS_Alloc(sizeof(Header) + capacity * elemSize));
    if (!header)
      return PR_FALSE;

    memcpy(header, mHdr, sizeof(Header) + Length() * elemSize);
  } else {
    // NS_Realloc existing data
    size_type size = sizeof(Header) + capacity * elemSize;
    header = static_cast<Header*>(NS_Realloc(mHdr, size));
    if (!header)
      return PR_FALSE;
  }

  header->mCapacity = capacity;
  mHdr = header;

  return PR_TRUE;
}
开发者ID:isleon,项目名称:Jaxer,代码行数:54,代码来源:nsTArray.cpp


示例2: ns_WildCardMatch

static int
ns_WildCardMatch(const T *str, const T *xp, bool case_insensitive)
{
    T *expr = nullptr;
    int x, ret = MATCH;

    if (!nsCharTraits<T>::find(xp, nsCharTraits<T>::length(xp), T('~')))
        return ::_shexp_match(str, xp, case_insensitive, 0);

    expr = (T *) NS_Alloc((nsCharTraits<T>::length(xp) + 1) * sizeof(T));
    if(!expr)
        return NOMATCH;
    memcpy(expr, xp, (nsCharTraits<T>::length(xp) + 1) * sizeof(T));

    x = ::_scan_and_copy(expr, T('~'), T('\0'), static_cast<T*>(nullptr));
    if (x != ABORTED && expr[x] == '~') {
        expr[x++] = '\0';
        ret = ::_shexp_match(str, &expr[x], case_insensitive, 0);
        switch (ret) {
        case NOMATCH: ret = MATCH;   break;
        case MATCH:   ret = NOMATCH; break;
        default:                     break;
        }
    }
    if (ret == MATCH)
        ret = ::_shexp_match(str, expr, case_insensitive, 0);

    NS_Free(expr);
    return ret;
}
开发者ID:abhishekvp,项目名称:gecko-dev,代码行数:30,代码来源:nsWildCard.cpp


示例3: NS_Alloc

/* void GetDictionaryList ([array, size_is (count)] out wstring dictionaries, out PRUint32 count); */
NS_IMETHODIMP mozHunspell::GetDictionaryList(PRUnichar ***aDictionaries,
                                            PRUint32 *aCount)
{
  if (!aDictionaries || !aCount)
    return NS_ERROR_NULL_POINTER;

  AppendNewStruct ans = {
    (PRUnichar**) NS_Alloc(sizeof(PRUnichar*) * mDictionaries.Count()),
    0,
    PR_FALSE
  };

  // This pointer is used during enumeration
  mDictionaries.EnumerateRead(AppendNewString, &ans);

  if (ans.failed) {
    while (ans.count) {
      --ans.count;
      NS_Free(ans.dics[ans.count]);
    }
    NS_Free(ans.dics);
    return NS_ERROR_OUT_OF_MEMORY;
  }

  *aDictionaries = ans.dics;
  *aCount = ans.count;

  return NS_OK;
}
开发者ID:LittleForker,项目名称:mozilla-central,代码行数:30,代码来源:mozHunspell.cpp


示例4: CFStringRefToUTF8Buffer

// Caller is responsible for freeing returned buffer.
static char* CFStringRefToUTF8Buffer(CFStringRef cfString)
{
  const char* buffer = ::CFStringGetCStringPtr(cfString, kCFStringEncodingUTF8);
  if (buffer) {
    return PL_strdup(buffer);
  }

  int bufferLength =
    ::CFStringGetMaximumSizeForEncoding(::CFStringGetLength(cfString),
                                        kCFStringEncodingUTF8) + 1;
  char* newBuffer = static_cast<char*>(NS_Alloc(bufferLength));
  if (!newBuffer) {
    return nullptr;
  }

  if (!::CFStringGetCString(cfString, newBuffer, bufferLength,
                            kCFStringEncodingUTF8)) {
    NS_Free(newBuffer);
    return nullptr;
  }

  newBuffer = static_cast<char*>(NS_Realloc(newBuffer,
                                            PL_strlen(newBuffer) + 1));
  return newBuffer;
}
开发者ID:hideakihata,项目名称:mozilla-central.fgv,代码行数:26,代码来源:nsPluginsDirDarwin.cpp


示例5: NS_ENSURE_ARG_POINTER

nsresult
sbSecurityMixin::CopyIIDArray(PRUint32 aCount, const nsIID **aSourceArray, nsIID ***aDestArray)
{
    NS_ENSURE_ARG_POINTER(aSourceArray);
    NS_ENSURE_ARG_POINTER(aDestArray);

    *aDestArray = 0;

    nsIID **iids = static_cast<nsIID**>( NS_Alloc( aCount * sizeof(nsIID*) ) );
    if (!iids) {
        return NS_ERROR_OUT_OF_MEMORY;
    }

    for (PRUint32 index = 0; index < aCount; ++index) {
        iids[index] = static_cast<nsIID*>( SB_CloneMemory( aSourceArray[index], sizeof(nsIID) ) );

        if (!iids[index]) {
            for (PRUint32 alloc_index = 0; alloc_index < index; ++alloc_index)
                NS_Free( iids[alloc_index] );
            NS_Free(iids);
            return NS_ERROR_OUT_OF_MEMORY;
        }
    }

    *aDestArray = iids;
    return NS_OK;
}
开发者ID:schorij23,项目名称:nightingale-hacking,代码行数:27,代码来源:sbSecurityMixin.cpp


示例6: NS_ENSURE_SUCCESS

nsresult
nsJSONWriter::WriteToStream(nsIOutputStream *aStream,
                            nsIUnicodeEncoder *encoder,
                            const PRUnichar *aBuffer,
                            uint32_t aLength)
{
  nsresult rv;
  int32_t srcLength = aLength;
  uint32_t bytesWritten;

  // The bytes written to the stream might differ from the PRUnichar size
  int32_t aDestLength;
  rv = encoder->GetMaxLength(aBuffer, srcLength, &aDestLength);
  NS_ENSURE_SUCCESS(rv, rv);

  // create the buffer we need
  char* destBuf = (char *) NS_Alloc(aDestLength);
  if (!destBuf)
    return NS_ERROR_OUT_OF_MEMORY;

  rv = encoder->Convert(aBuffer, &srcLength, destBuf, &aDestLength);
  if (NS_SUCCEEDED(rv))
    rv = aStream->Write(destBuf, aDestLength, &bytesWritten);

  NS_Free(destBuf);
  mDidWrite = true;

  return rv;
}
开发者ID:SoulTrader,项目名称:mozilla-central,代码行数:29,代码来源:nsJSON.cpp


示例7: TestInterfaceIs

/* void testInterfaceIs (in nsIIDPtr aIID, [iid_is (aIID)] in nsQIResult a,
 *                       inout nsIIDPtr bIID, [iid_is (bIID)] inout nsQIResult b,
 *                       out nsIIDPtr rvIID, [iid_is (rvIID), retval] out nsQIResult rv); */
NS_IMETHODIMP nsXPCTestParams::TestInterfaceIs(const nsIID *aIID, void *a,
                                               nsIID **bIID, void **b,
                                               nsIID **rvIID, void **rv)
{
    //
    // Getting the buffers and ownership right here can be a little tricky.
    //

    // The interface pointers are heap-allocated, and b has been AddRef'd
    // by XPConnect for the duration of the call. If we snatch it away from b
    // and leave no trace, XPConnect won't Release it. Since we also need to
    // return an already-AddRef'd pointer in rv, we don't need to do anything
    // special here.
    *rv = *b;

    // rvIID is out-only, so nobody allocated an IID buffer for us. Do that now,
    // and store b's IID in the new buffer.
    *rvIID = static_cast<nsIID*>(NS_Alloc(sizeof(nsID)));
    if (!*rvIID)
        return NS_ERROR_OUT_OF_MEMORY;
    **rvIID = **bIID;

    // Copy the interface pointer from a to b. Since a is in-only, XPConnect will
    // release it upon completion of the call. AddRef it for b.
    *b = a;
    static_cast<nsISupports*>(*b)->AddRef();

    // We already had a buffer allocated for b's IID, so we can re-use it.
    **bIID = *aIID;

    return NS_OK;
}
开发者ID:aeddi,项目名称:gecko-dev,代码行数:35,代码来源:xpctest_params.cpp


示例8: chan

NS_IMETHODIMP 
nsStreamLoader::OnStartRequest(nsIRequest* request, nsISupports *ctxt)
{
  nsCOMPtr<nsIChannel> chan( do_QueryInterface(request) );
  if (chan) {
    int64_t contentLength = -1;
    chan->GetContentLength(&contentLength);
    if (contentLength >= 0) {
      if (contentLength > UINT32_MAX) {
        // Too big to fit into uint32, so let's bail.
        // XXX we should really make mAllocated and mLength 64-bit instead.
        return NS_ERROR_OUT_OF_MEMORY;
      }
      uint32_t contentLength32 = uint32_t(contentLength);
      // preallocate buffer
      mData = static_cast<uint8_t*>(NS_Alloc(contentLength32));
      if (!mData) {
        return NS_ERROR_OUT_OF_MEMORY;
      }
      mAllocated = contentLength32;
    }
  }
  mContext = ctxt;
  return NS_OK;
}
开发者ID:AshishNamdev,项目名称:mozilla-central,代码行数:25,代码来源:nsStreamLoader.cpp


示例9: NS_Alloc

NS_COM_GLUE void*
nsMemory::Clone(const void* ptr, PRSize size)
{
    void* newPtr = NS_Alloc(size);
    if (newPtr)
        memcpy(newPtr, ptr, size);
    return newPtr;
}
开发者ID:lofter2011,项目名称:Icefox,代码行数:8,代码来源:nsMemory.cpp


示例10: NS_ENSURE_SUCCESS

nsresult
QTAtomReader::GetFairPlayUserName(nsAString& aUserName)
{
  PRUint32 atom[2];
  PRUint64 offset = 0;
  nsresult rv;

  // Get the starting end offset.
  PRInt64  fileSize;
  PRUint64 endOffset;
  rv = mFile->GetFileSize(&fileSize);
  NS_ENSURE_SUCCESS(rv, rv);
  endOffset = fileSize;

  // Set the atom header size.
  mAtomHdrSize = 8;

  // Get the sample description table atom.
  rv = AtomPathGet("/moov/trak/mdia/minf/stbl/stsd",
                   &atom,
                   &offset,
                   &endOffset);
  NS_ENSURE_SUCCESS(rv, rv);

  // Get the FairPlay DRM atom, skipping the sample description table
  // atom header.
  offset += 16;
  rv = AtomPathGet("/drms", &atom, &offset, &endOffset);
  NS_ENSURE_SUCCESS(rv, rv);

  // Get the FairPlay user name atom, skipping the FairPlay DRM atom header.
  offset += 0x24;
  rv = AtomPathGet("/sinf/schi/name", &atom, &offset, &endOffset);
  NS_ENSURE_SUCCESS(rv, rv);

  // Get the FairPlay user name size and offset.
  offset += 8;
  PRUint32 userNameSize = (PRUint32)(endOffset - offset);

  // Allocate a user name buffer and set up for auto-disposal.
  char* userNameBuffer = (char*) NS_Alloc(userNameSize + 1);
  NS_ENSURE_TRUE(userNameBuffer, NS_ERROR_OUT_OF_MEMORY);
  sbAutoNSMemPtr autoUserNameBuffer(userNameBuffer);

  // Read the user name.
  PRUint32 bytesRead;
  rv = mSeekableStream->Seek(nsISeekableStream::NS_SEEK_SET, offset);
  NS_ENSURE_SUCCESS(rv, rv);
  rv = mInputStream->Read(userNameBuffer, userNameSize, &bytesRead);
  NS_ENSURE_SUCCESS(rv, rv);
  NS_ENSURE_TRUE(bytesRead >= userNameSize, NS_ERROR_FAILURE);
  userNameBuffer[userNameSize] = '\0';

  // Return results.
  aUserName.Assign(NS_ConvertUTF8toUTF16(userNameBuffer));

  return NS_OK;
}
开发者ID:Brijen,项目名称:nightingale-hacking,代码行数:58,代码来源:QTAtomReader.cpp


示例11: NS_ENSURE_ARG_POINTER

/* readonly attribute nsIDPtr controllerId; */
NS_IMETHODIMP sbMockDevice::GetControllerId(nsID * *aControllerId)
{
  NS_ENSURE_ARG_POINTER(aControllerId);

  *aControllerId = (nsID*)NS_Alloc(sizeof(nsID));
  NS_ENSURE_TRUE(*aControllerId, NS_ERROR_OUT_OF_MEMORY);
  **aControllerId = NS_GET_IID(nsISupports);
  return NS_OK;
}
开发者ID:Brijen,项目名称:nightingale-hacking,代码行数:10,代码来源:sbMockDevice.cpp


示例12: wxToUnichar

PRUnichar* wxToUnichar(const wxString& wxstr)
{
    size_t i,len = wxstr.Length();
    PRUnichar* ret = (PRUnichar*)NS_Alloc((len+1) * sizeof(PRUnichar));
    for (i = 0; i < len; ++i)
        *(ret+i) = (PRUnichar)wxstr.GetChar(i);
    *(ret+len) = 0;
    return ret;
}
开发者ID:BBkBlade,项目名称:e,代码行数:9,代码来源:nsimpl.cpp


示例13: moz_gdk_pixbuf_to_channel

static nsresult
moz_gdk_pixbuf_to_channel(GdkPixbuf* aPixbuf, nsIURI *aURI,
                          nsIChannel **aChannel)
{
  int width = gdk_pixbuf_get_width(aPixbuf);
  int height = gdk_pixbuf_get_height(aPixbuf);
  NS_ENSURE_TRUE(height < 256 && width < 256 && height > 0 && width > 0 &&
                 gdk_pixbuf_get_colorspace(aPixbuf) == GDK_COLORSPACE_RGB &&
                 gdk_pixbuf_get_bits_per_sample(aPixbuf) == 8 &&
                 gdk_pixbuf_get_has_alpha(aPixbuf) &&
                 gdk_pixbuf_get_n_channels(aPixbuf) == 4,
                 NS_ERROR_UNEXPECTED);

  const int n_channels = 4;
  gsize buf_size = 3 + n_channels * height * width;
  PRUint8 * const buf = (PRUint8*)NS_Alloc(buf_size);
  NS_ENSURE_TRUE(buf, NS_ERROR_OUT_OF_MEMORY);
  PRUint8 *out = buf;

  *(out++) = width;
  *(out++) = height;
  *(out++) = 8; // bits of alpha per pixel
  
  const guchar * const pixels = gdk_pixbuf_get_pixels(aPixbuf);
  int rowextra = gdk_pixbuf_get_rowstride(aPixbuf) - width * n_channels;

  // encode the RGB data and the A data
  const guchar * in = pixels;
  PRUint8 *alpha_out = out + height * width * 3;
#ifdef DEBUG
  PRUint8 * const alpha_start = alpha_out;
#endif
  for (int y = 0; y < height; ++y, in += rowextra) {
    for (int x = 0; x < width; ++x) {
      *(out++) = *(in++); // R
      *(out++) = *(in++); // G
      *(out++) = *(in++); // B
      *(alpha_out++) = *(in++); // A
    }
  }

  NS_ASSERTION(out == alpha_start && alpha_out == buf + buf_size,
               "size miscalculation");

  nsresult rv;
  nsCOMPtr<nsIInputStream> stream;
  rv = NS_NewByteInputStream(getter_AddRefs(stream), (char*)buf, buf_size);
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsIStringInputStream> sstream = do_QueryInterface(stream);
  sstream->AdoptData((char*)buf, buf_size); // previous call was |ShareData|

  rv = NS_NewInputStreamChannel(aChannel, aURI, stream,
                                NS_LITERAL_CSTRING("image/icon"));
  return rv;
}
开发者ID:rn10950,项目名称:RetroZilla,代码行数:56,代码来源:nsIconChannel.cpp


示例14: p2cstrdup

static char* p2cstrdup(StringPtr pstr)
{
  int len = pstr[0];
  char* cstr = static_cast<char*>(NS_Alloc(len + 1));
  if (cstr) {
    memmove(cstr, pstr + 1, len);
    cstr[len] = '\0';
  }
  return cstr;
}
开发者ID:hideakihata,项目名称:mozilla-central.fgv,代码行数:10,代码来源:nsPluginsDirDarwin.cpp


示例15: NS_strndup

char16_t*
NS_strndup(const char16_t* aString, uint32_t aLen)
{
  char16_t* newBuf = (char16_t*)NS_Alloc((aLen + 1) * sizeof(char16_t));
  if (newBuf) {
    memcpy(newBuf, aString, aLen * sizeof(char16_t));
    newBuf[aLen] = '\0';
  }
  return newBuf;
}
开发者ID:ashishrana7,项目名称:firefox,代码行数:10,代码来源:nsCRTGlue.cpp


示例16: CFStringRefToUTF8Buffer

// Caller is responsible for freeing returned buffer.
static char* CFStringRefToUTF8Buffer(CFStringRef cfString)
{
  int bufferLength = ::CFStringGetLength(cfString) + 1;
  char* newBuffer = static_cast<char*>(NS_Alloc(bufferLength));
  if (newBuffer && !::CFStringGetCString(cfString, newBuffer, bufferLength, kCFStringEncodingUTF8)) {
    NS_Free(newBuffer);
    newBuffer = nsnull;
  }
  return newBuffer;
}
开发者ID:amyvmiwei,项目名称:firefox,代码行数:11,代码来源:nsPluginsDirDarwin.cpp


示例17: NS_strndup

PRUnichar*
NS_strndup(const PRUnichar *aString, PRUint32 aLen)
{
  PRUnichar *newBuf = (PRUnichar*) NS_Alloc((aLen + 1) * sizeof(PRUnichar));
  if (newBuf) {
    memcpy(newBuf, aString, aLen * sizeof(PRUnichar));
    newBuf[aLen] = '\0';
  }
  return newBuf;
}
开发者ID:Akin-Net,项目名称:mozilla-central,代码行数:10,代码来源:nsCRTGlue.cpp


示例18: CallGetService

NS_IMETHODIMP  nsTextToSubURI::ConvertAndEscape(
  const char *charset, const PRUnichar *text, char **_retval) 
{
  if(nullptr == _retval)
    return NS_ERROR_NULL_POINTER;
  *_retval = nullptr;
  nsresult rv = NS_OK;
  
  // Get Charset, get the encoder.
  nsICharsetConverterManager *ccm;
  rv = CallGetService(kCharsetConverterManagerCID, &ccm);
  if(NS_SUCCEEDED(rv)) {
     nsIUnicodeEncoder *encoder;
     rv = ccm->GetUnicodeEncoder(charset, &encoder);
     NS_RELEASE(ccm);
     if (NS_SUCCEEDED(rv)) {
       rv = encoder->SetOutputErrorBehavior(nsIUnicodeEncoder::kOnError_Replace, nullptr, (PRUnichar)'?');
       if(NS_SUCCEEDED(rv))
       {
          char buf[256];
          char *pBuf = buf;
          int32_t ulen = text ? NS_strlen(text) : 0;
          int32_t outlen = 0;
          if(NS_SUCCEEDED(rv = encoder->GetMaxLength(text, ulen, &outlen))) 
          {
             if(outlen >= 256) {
                pBuf = (char*)NS_Alloc(outlen+1);
             }
             if(nullptr == pBuf) {
                outlen = 255;
                pBuf = buf;
             }
             int32_t bufLen = outlen;
             if(NS_SUCCEEDED(rv = encoder->Convert(text,&ulen, pBuf, &outlen))) {
                // put termination characters (e.g. ESC(B of ISO-2022-JP) if necessary
                int32_t finLen = bufLen - outlen;
                if (finLen > 0) {
                  if (NS_SUCCEEDED(encoder->Finish((char *)(pBuf+outlen), &finLen)))
                    outlen += finLen;
                }
                pBuf[outlen] = '\0';
                *_retval = nsEscape(pBuf, url_XPAlphas);
                if(nullptr == *_retval)
                  rv = NS_ERROR_OUT_OF_MEMORY;
             }
          }
          if(pBuf != buf)
             NS_Free(pBuf);
       }
       NS_RELEASE(encoder);
     }
  }
  
  return rv;
}
开发者ID:AshishNamdev,项目名称:mozilla-central,代码行数:55,代码来源:nsTextToSubURI.cpp


示例19: NS_strdup

char*
NS_strdup(const char *aString)
{
  PRUint32 len = strlen(aString);
  char *str = (char*) NS_Alloc(len + 1);
  if (str) {
    memcpy(str, aString, len);
    str[len] = '\0';
  }
  return str;
}
开发者ID:Akin-Net,项目名称:mozilla-central,代码行数:11,代码来源:nsCRTGlue.cpp


示例20: NS_ENSURE_ARG_POINTER

NS_IMETHODIMP
sbCDDeviceMarshall::GetId(nsID **aId)
{
  NS_ENSURE_ARG_POINTER(aId);

  static nsID const id = SB_CDDEVICE_MARSHALL_CID;
  *aId = static_cast<nsID *>(NS_Alloc(sizeof(nsID)));
  **aId = id;

  return NS_OK;
}
开发者ID:AntoineTurmel,项目名称:nightingale-hacking,代码行数:11,代码来源:sbCDDeviceMarshall.cpp



注:本文中的NS_Alloc函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ NS_CStringGetData函数代码示例发布时间:2022-05-30
下一篇:
C++ NS_ASSERTION函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap