# persistent memory management

- Thread: https://externals.io/message/26765
- Original archive: https://news-web.php.net/php.internals/26765
- Started by Alexey Zakhlestin on 2006-12-02T20:33:56+00:00
- Messages: 6
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #26765 — Alexey Zakhlestin — 2006-12-02T20:33:56+00:00

URL: https://externals.io/message/26765#26765

Hi.

I am trying to make my first php extension :)
I am sorry, if the question would be too newbiesh, but I just couldn't
find a more correct place to ask

here is the code:
http://loccache.googlecode.com/svn/trunk/loccache.c

I am trying to do the following:
at the minit-phase I am allocating a persistent HashTable
extension has 4 funcitons:
     * loc_set($namespace, $varname, $value); // stores $value
     * loc_get($namespace, $varname) // returns $value from storage
     * loc_isset($namespace, $varname) // returns bool
     * loc_unset($namespace, $varname) // removes varname from storage
during loc_set, I chech if there is "$namespace" item in my persistent
hashtable, and if there isn't, I create it as a child hashtable
$varname is a key in that second HashTable and $value is the value

something like:
$big_persistent_hash = array(
      $namespace => array(
          $varname => $value
      )
);

extension build and even tends to work... kinda..

unfortunately, persistent values are not too persistent in my case, and i
keep getting memory errors.
I would be grateful for any help. the source code is not too big :)

---

## #26770 — Matt Wilmas — 2006-12-03T09:49:15+00:00

URL: https://externals.io/message/26765#26770 · In reply to: #26765

Hi Alexey,

Not sure what the exact problem is, or if this is related, but in your
loc_set() function's zend_hash_add() calls, you have sizeof(HashTable) and
sizeof(zval).  Shouldn't both of those be sizeof(HashTable *) ? :-)


Matt


----- Original Message ----- 
From: "Alexey Zakhlestin"
Sent: Saturday, December 02, 2006

Hi.

I am trying to make my first php extension :)
I am sorry, if the question would be too newbiesh, but I just couldn't
find a more correct place to ask

here is the code:
http://loccache.googlecode.com/svn/trunk/loccache.c

I am trying to do the following:
at the minit-phase I am allocating a persistent HashTable
extension has 4 funcitons:
     * loc_set($namespace, $varname, $value); // stores $value
     * loc_get($namespace, $varname) // returns $value from storage
     * loc_isset($namespace, $varname) // returns bool
     * loc_unset($namespace, $varname) // removes varname from storage
during loc_set, I chech if there is "$namespace" item in my persistent
hashtable, and if there isn't, I create it as a child hashtable
$varname is a key in that second HashTable and $value is the value

something like:
$big_persistent_hash = array(
      $namespace => array(
          $varname => $value
      )
);

extension build and even tends to work... kinda..

unfortunately, persistent values are not too persistent in my case, and i
keep getting memory errors.
I would be grateful for any help. the source code is not too big :)

---

## #26772 — Alexey Zakhlestin — 2006-12-03T11:52:14+00:00

URL: https://externals.io/message/26765#26772 · In reply to: #26770

> Hi Alexey,
>
> Not sure what the exact problem is, or if this is related, but in your
> loc_set() function's zend_hash_add() calls, you have sizeof(HashTable) and
> sizeof(zval).  Shouldn't both of those be sizeof(HashTable *) ? :-)

(HashTable *) and (zval *), actually
thanks

-- 
Alexey Zakhlestin
http://blog.milkfarmsoft.com/

---

## #26774 — Matt Wilmas — 2006-12-03T12:26:53+00:00

URL: https://externals.io/message/26765#26774 · In reply to: #26772

Hi Alexey,

----- Original Message -----
From: "Alexey Zakhlestin"
Sent: Sunday, December 03, 2006

> 
> > […]
and
> > […]
>
> (HashTable *) and (zval *), actually
> thanks

Well, your variables being added, g_ht and ns_ht, are both HashTable * ,
so... ;-)

> Alexey Zakhlestin
> http://blog.milkfarmsoft.com/

Matt

---

## #26775 — Alexey Zakhlestin — 2006-12-03T12:41:52+00:00

URL: https://externals.io/message/26765#26775 · In reply to: #26774

first zend_hash_add adds ns_ht, so it is (HashTable *)
second zend_hash_add adds p_val, so it is (zval *)

am I missing something obvious?


> Hi Alexey,
>
> ----- Original Message -----
> From: "Alexey Zakhlestin"
> Sent: Sunday, December 03, 2006
>
> > […]
> and
> > […]
>
> Well, your variables being added, g_ht and ns_ht, are both HashTable * ,
> so... ;-)
>
> > […]
>
> Matt
>
>


-- 
Alexey Zakhlestin
http://blog.milkfarmsoft.com/

---

## #26776 — Matt Wilmas — 2006-12-03T13:04:16+00:00

URL: https://externals.io/message/26765#26776 · In reply to: #26775

Hi Alexey,

Whoops!  Ugh, I was looking at the first param of zend_hash_add(). :-O
You're correct then, sorry! :-/

Matt


----- Original Message -----
From: "Alexey Zakhlestin"
Sent: Sunday, December 03, 2006

> first zend_hash_add adds ns_ht, so it is (HashTable *)
> second zend_hash_add adds p_val, so it is (zval *)
>
> am I missing something obvious?
>
> --
> Alexey Zakhlestin
> http://blog.milkfarmsoft.com/
